home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as.sun3 / RCS / m68k.c,v < prev    next >
Encoding:
Text File  |  1990-02-16  |  75.7 KB  |  3,410 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.02.16.13.54.42;  author rab;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.01.06.14.18.52;  author rab;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @#ifdef'ed out `void *' declaration so it will compile on a ds3100
  27. ultrix compiler.
  28. @
  29. text
  30. @/* m68k.c  All the m68020 specific stuff in one convenient, huge,
  31.    slow to compile, easy to find file.
  32.    Copyright (C) 1987 Free Software Foundation, Inc.
  33.  
  34. This file is part of GAS, the GNU Assembler.
  35.  
  36. GAS is free software; you can redistribute it and/or modify
  37. it under the terms of the GNU General Public License as published by
  38. the Free Software Foundation; either version 1, or (at your option)
  39. any later version.
  40.  
  41. GAS is distributed in the hope that it will be useful,
  42. but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  44. GNU General Public License for more details.
  45.  
  46. You should have received a copy of the GNU General Public License
  47. along with GAS; see the file COPYING.  If not, write to
  48. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  49.  
  50. #include <stdio.h>
  51. #include <ctype.h>
  52.  
  53. #include "m68k-opcode.h"
  54. #include "as.h"
  55. #include "obstack.h"
  56. #include "frags.h"
  57. #include "struc-symbol.h"
  58. #include "flonum.h"
  59. #include "expr.h"
  60. #include "hash.h"
  61. #include "md.h"
  62. #include "m68k.h"
  63.  
  64. #ifdef M_SUN
  65. /* This variable contains the value to write out at the beginning of
  66.    the a.out file.  The 2<<16 means that this is a 68020 file instead
  67.    of an old-style 68000 file */
  68.  
  69. long omagic = 2<<16|OMAGIC;    /* Magic byte for header file */
  70. #else
  71. long omagic = OMAGIC;
  72. #endif
  73.  
  74.  
  75. /* This array holds the chars that always start a comment.  If the
  76.    pre-processor is disabled, these aren't very useful */
  77. char comment_chars[] = "|";
  78.  
  79. /* This array holds the chars that only start a comment at the beginning of
  80.    a line.  If the line seems to have the form '# 123 filename'
  81.    .line and .file directives will appear in the pre-processed output */
  82. /* Note that input_file.c hand checks for '#' at the beginning of the
  83.    first line of the input file.  This is because the compiler outputs
  84.    #NO_APP at the beginning of its output. */
  85. /* Also note that '/*' will always start a comment */
  86. char line_comment_chars[] = "#";
  87.  
  88. /* Chars that can be used to separate mant from exp in floating point nums */
  89. char EXP_CHARS[] = "eE";
  90.  
  91. /* Chars that mean this number is a floating point constant */
  92. /* As in 0f12.456 */
  93. /* or    0d1.2345e12 */
  94.  
  95. char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  96.  
  97. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  98.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  99.    but nothing is ideal around here.
  100.  */
  101.  
  102. void fix_new();
  103. void install_operand();
  104. void install_gen_operand();
  105.  
  106. /* Its an arbitrary name:  This means I don't approve of it */
  107. /* See flames below */
  108. struct obstack robyn;
  109.  
  110. #define TAB(x,y)    (((x)<<2)+(y))
  111. #define TABTYPE(xy)     ((xy) >> 2)
  112. #define BYTE        0
  113. #define SHORT        1
  114. #define LONG        2
  115. #define SZ_UNDEF    3
  116.  
  117. #define BRANCH        1
  118. #define FBRANCH        2
  119. #define PCREL        3
  120. #define BCC68000        4
  121. #define DBCC            5
  122.  
  123. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  124.    on the 68000.  The 68000 doesn't support long branches with branchs */
  125.  
  126. /* This table desribes how you change sizes for the various types of variable
  127.    size expressions.  This version only supports two kinds. */
  128.  
  129. /* Note that calls to frag_var need to specify the maximum expansion needed */
  130. /* This is currently 10 bytes for DBCC */
  131.  
  132. /* The fields are:
  133.     How far Forward this mode will reach:
  134.     How far Backward this mode will reach:
  135.     How many bytes this mode will add to the size of the frag
  136.     Which mode to go to if the offset won't fit in this one
  137.  */
  138. relax_typeS
  139. md_relax_table[] = {
  140. { 1,        1,        0,    0 },    /* First entries aren't used */
  141. { 1,        1,        0,    0 },    /* For no good reason except */
  142. { 1,        1,        0,    0 },    /* that the VAX doesn't either */
  143. { 1,        1,        0,    0 },
  144.  
  145. { (127),    (-128),        0,    TAB(BRANCH,SHORT)},
  146. { (2+32767),    (2+-32768),    2,    TAB(BRANCH,LONG) },
  147. { 0,        0,        4,    0 },
  148. { 1,        1,        0,    0 },
  149.  
  150. { 1,        1,        0,    0 },    /* FBRANCH doesn't come BYTE */
  151. { (2+32767),    (2+-32768),    2,    TAB(FBRANCH,LONG)},
  152. { 0,        0,        4,    0 },
  153. { 1,        1,        0,    0 },
  154.  
  155. { 1,        1,        0,    0 },    /* PCREL doesn't come BYTE */
  156. { (2+32767),    (2+-32768),    2,    TAB(PCREL,LONG)},
  157. { 0,        0,        4,    0 },
  158. { 1,        1,        0,    0 },
  159.  
  160. { (127),        (-128),         0,      TAB(BCC68000,SHORT)},
  161. { (2+32767),    (2+-32768),     2,      TAB(BCC68000,LONG) },
  162. { 0,            0,              6,      0 },  /* jmp long space */
  163. { 1,            1,              0,      0 },
  164.  
  165. { 1,            1,              0,      0 },  /* DBCC doesn't come BYTE */
  166. { (2+32767),    (2+-32768),     2,      TAB(DBCC,LONG) },
  167. { 0,            0,             10,      0 },  /* bra/jmp long space */
  168. { 1,            1,              0,      0 },
  169.  
  170. };
  171.  
  172. void    s_data1(),    s_data2(),    s_even(),    s_space();
  173. void    float_cons();
  174.  
  175. /* These are the machine dependent pseudo-ops.  These are included so
  176.    the assembler can work on the output from the SUN C compiler, which
  177.    generates these.
  178.  */
  179.  
  180. /* This table describes all the machine specific pseudo-ops the assembler
  181.    has to support.  The fields are:
  182.          pseudo-op name without dot
  183.       function to call to execute this pseudo-op
  184.       Integer arg to pass to the function
  185.  */
  186. pseudo_typeS md_pseudo_table[] = {
  187.     { "data1",    s_data1,    0    },
  188.     { "data2",    s_data2,    0    },
  189.     { "even",    s_even,        0    },
  190.     { "skip",    s_space,    0    },
  191.     { 0,        0,        0    }
  192. };
  193.  
  194.  
  195. /* #define isbyte(x)    ((x)>=-128 && (x)<=127) */
  196. /* #define isword(x)    ((x)>=-32768 && (x)<=32767) */
  197.  
  198. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  199. #define isubyte(x)    ((x)>=0 && (x)<=255)
  200. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  201. #define isuword(x)    ((x)>=0 && (x)<=65535)
  202.  
  203. #define isbyte(x)    ((x)>=-128 && (x)<=255)
  204. #define isword(x)    ((x)>=-32768 && (x)<=65535)
  205. #define islong(x)    (1)
  206.  
  207. char *input_line_pointer;
  208.  
  209. /* Operands we can parse:  (And associated modes)
  210.  
  211. numb:    8 bit num
  212. numw:    16 bit num
  213. numl:    32 bit num
  214. dreg:    data reg 0-7
  215. reg:    address or data register
  216. areg:    address register
  217. apc:    address register, PC, ZPC or empty string
  218. num:    16 or 32 bit num
  219. num2:    like num
  220. sz:    w or l        if omitted, l assumed
  221. scale:    1 2 4 or 8    if omitted, 1 assumed
  222.  
  223. 7.4 IMMED #num                --> NUM
  224. 0.? DREG  dreg                --> dreg
  225. 1.? AREG  areg                --> areg
  226. 2.? AINDR areg@@                --> *(areg)
  227. 3.? AINC  areg@@+            --> *(areg++)
  228. 4.? ADEC  areg@@-            --> *(--areg)
  229. 5.? AOFF  apc@@(numw)            --> *(apc+numw)    -- empty string and ZPC not allowed here
  230. 6.? AINDX apc@@(num,reg:sz:scale)    --> *(apc+num+reg*scale)
  231. 6.? AINDX apc@@(reg:sz:scale)        --> same, with num=0
  232. 6.? APODX apc@@(num)@@(num2,reg:sz:scale)    --> *(*(apc+num)+num2+reg*scale)
  233. 6.? APODX apc@@(num)@@(reg:sz:scale)    --> same, with num2=0
  234. 6.? AMIND apc@@(num)@@(num2)        --> *(*(apc+num)+num2) (previous mode without an index reg)
  235. 6.? APRDX apc@@(num,reg:sz:scale)@@(num2)    --> *(*(apc+num+reg*scale)+num2)
  236. 6.? APRDX apc@@(reg:sz:scale)@@(num2)    --> same, with num=0
  237. 7.0 ABSL  num:sz            --> *(num)
  238.           num                --> *(num) (sz L assumed)
  239. *** MSCR  otherreg            --> Magic
  240. With -l option
  241. 5.? AOFF  apc@@(num)            --> *(apc+num) -- empty string and ZPC not allowed here still
  242.  
  243. examples:
  244.     #foo    #0x35    #12
  245.     d2
  246.     a4
  247.     a3@@
  248.     a5@@+
  249.     a6@@-
  250.     a2@@(12)    pc@@(14)
  251.     a1@@(5,d2:w:1)    @@(45,d6:l:4)
  252.     pc@@(a2)        @@(d4)
  253.     etc . . .
  254.  
  255.  
  256. #name@@(numw)    -->turn into PC rel mode
  257. apc@@(num8,reg:sz:scale)        --> *(apc+num8+reg*scale)
  258.  
  259. */
  260.  
  261. #define IMMED    1
  262. #define DREG    2
  263. #define AREG    3
  264. #define AINDR    4
  265. #define ADEC    5
  266. #define AINC    6
  267. #define AOFF    7
  268. #define AINDX    8
  269. #define APODX    9
  270. #define AMIND    10
  271. #define APRDX    11
  272. #define ABSL    12
  273. #define MSCR    13
  274. #define REGLST    14
  275.  
  276. #define FAIL    0
  277. #define OK    1
  278.  
  279. /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
  280.    8-15==addr reg for operands that take both types */
  281. #define DATA    1        /*   1- 8 == data registers 0-7 */
  282. #define ADDR    (DATA+8)    /*   9-16 == address regs 0-7 */
  283. #define FPREG    (ADDR+8)    /*  17-24 Eight FP registers */
  284. #define COPNUM    (FPREG+8)    /*  25-32 Co-processor #1-#8 */
  285.  
  286. #define PC    (COPNUM+8)    /*  33 Program counter */
  287. #define ZPC    (PC+1)        /*  34 Hack for Program space, but 0 addressing */
  288. #define SR    (ZPC+1)        /*  35 Status Reg */
  289. #define CCR    (SR+1)        /*  36 Condition code Reg */
  290.  
  291. /* These have to be in order for the movec instruction to work. */
  292. #define USP    (CCR+1)        /*  37 User Stack Pointer */
  293. #define ISP    (USP+1)        /*  38 Interrupt stack pointer */
  294. #define SFC    (ISP+1)        /*  39 */
  295. #define DFC    (SFC+1)        /*  40 */
  296. #define CACR    (DFC+1)        /*  41 */
  297. #define VBR    (CACR+1)    /*  42 */
  298. #define CAAR    (VBR+1)        /*  43 */
  299. #define MSP    (CAAR+1)    /*  44 */
  300.  
  301. #define FPI    (MSP+1)        /* 45 */
  302. #define FPS    (FPI+1)        /* 46 */
  303. #define FPC    (FPS+1)        /* 47 */
  304. /*
  305.  * these defines should be in m68k.c but
  306.  * i put them here to keep all the m68851 stuff
  307.  * together -rab
  308.  * JF--Make sure these #s don't clash with the ones in m68k.c
  309.  * That would be BAD.
  310.  */
  311. #define TC    (FPC+1)        /* 48 */
  312. #define DRP    (TC+1)        /* 49 */
  313. #define SRP    (DRP+1)        /* 50 */
  314. #define CRP    (SRP+1)        /* 51 */
  315. #define CAL    (CRP+1)        /* 52 */
  316. #define VAL    (CAL+1)        /* 53 */
  317. #define SCC    (VAL+1)        /* 54 */
  318. #define AC    (SCC+1)        /* 55 */
  319. #define BAD    (AC+1)        /* 56,57,58,59, 60,61,62,63 */
  320. #define BAC    (BAD+8)        /* 64,65,66,67, 68,69,70,71 */
  321. #define PSR    (BAC+8)        /* 72 */
  322. #define PCSR    (PSR+1)        /* 73 */
  323.  
  324.  
  325. /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
  326. /* I think. . .  */
  327.  
  328. #define    SP    ADDR+7
  329.  
  330. /* JF these tables here are for speed at the expense of size */
  331. /* You can replace them with the #if 0 versions if you really
  332.    need space and don't mind it running a bit slower */
  333.  
  334. static char mklower_table[256];
  335. #define mklower(c) (mklower_table[(unsigned char)(c)])
  336. static char notend_table[256];
  337. static char alt_notend_table[256];
  338. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  339.  alt_notend_table[(unsigned char)(s[1])])))
  340.  
  341. #if 0
  342. #define mklower(c)    (isupper(c) ? tolower(c) : c)
  343. #endif
  344.  
  345.  
  346. struct m68k_exp {
  347.     char    *e_beg;
  348.     char    *e_end;
  349.     expressionS e_exp;
  350.     short    e_siz;        /* 0== default 1==short/byte 2==word 3==long */
  351. };
  352.  
  353. /* Internal form of an operand.  */
  354. struct m68k_op {
  355.     char    *error;        /* Couldn't parse it */
  356.     int    mode;        /* What mode this instruction is in.  */
  357.     unsigned long int    reg;        /* Base register */
  358.     struct m68k_exp *con1;
  359.     int    ireg;        /* Index register */
  360.     int    isiz;        /* 0==unspec  1==byte(?)  2==short  3==long  */
  361.     int    imul;        /* Multipy ireg by this (1,2,4,or 8) */
  362.     struct    m68k_exp *con2;
  363. };
  364.  
  365. /* internal form of a 68020 instruction */
  366. struct m68_it {
  367.     char    *error;
  368.     char    *args;        /* list of opcode info */
  369.     int    numargs;
  370.  
  371.     int    numo;        /* Number of shorts in opcode */
  372.     short    opcode[11];
  373.  
  374.     struct m68k_op operands[6];
  375.  
  376.     int    nexp;        /* number of exprs in use */
  377.     struct m68k_exp exprs[4];
  378.  
  379.     int    nfrag;        /* Number of frags we have to produce */
  380.     struct {
  381.         int fragoff;    /* Where in the current opcode[] the frag ends */
  382.         symbolS *fadd;
  383.         long int foff;
  384.         int fragty;
  385.     } fragb[4];
  386.  
  387.     int    nrel;        /* Num of reloc strucs in use */
  388.     struct    {
  389.         int    n;
  390.         symbolS    *add,
  391.             *sub;
  392.         long int off;
  393.         char    wid;
  394.         char    pcrel;
  395.     } reloc[5];        /* Five is enough??? */
  396. };
  397.  
  398. struct m68_it the_ins;        /* the instruction being assembled */
  399.  
  400.  
  401. /* Macros for adding things to the m68_it struct */
  402.  
  403. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  404.  
  405. /* Like addword, but goes BEFORE general operands */
  406. #define insop(w)    {int z;\
  407.  for(z=the_ins.numo;z>opcode->m_codenum;--z)\
  408.    the_ins.opcode[z]=the_ins.opcode[z-1];\
  409.  for(z=0;z<the_ins.nrel;z++)\
  410.    the_ins.reloc[z].n+=2;\
  411.  the_ins.opcode[opcode->m_codenum]=w;\
  412.  the_ins.numo++;\
  413. }
  414.  
  415.  
  416. #define add_exp(beg,end) (\
  417.     the_ins.exprs[the_ins.nexp].e_beg=beg,\
  418.     the_ins.exprs[the_ins.nexp].e_end=end,\
  419.     &the_ins.exprs[the_ins.nexp++]\
  420. )
  421.  
  422.  
  423. /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
  424. #define add_fix(width,exp,pc_rel) {\
  425.     the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
  426.         (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
  427.     the_ins.reloc[the_ins.nrel].add=adds((exp));\
  428.     the_ins.reloc[the_ins.nrel].sub=subs((exp));\
  429.     the_ins.reloc[the_ins.nrel].off=offs((exp));\
  430.     the_ins.reloc[the_ins.nrel].wid=width;\
  431.     the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
  432. }
  433.  
  434. #define add_frag(add,off,type)  {\
  435.     the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
  436.     the_ins.fragb[the_ins.nfrag].fadd=add;\
  437.     the_ins.fragb[the_ins.nfrag].foff=off;\
  438.     the_ins.fragb[the_ins.nfrag++].fragty=type;\
  439. }
  440.  
  441. #define isvar(exp)    ((exp) && (adds(exp) || subs(exp)))
  442.  
  443. #define seg(exp)    ((exp)->e_exp.X_seg)
  444. #define adds(exp)    ((exp)->e_exp.X_add_symbol)
  445. #define subs(exp)    ((exp)->e_exp.X_subtract_symbol)
  446. #define offs(exp)    ((exp)->e_exp.X_add_number)
  447.  
  448.  
  449. struct m68_incant {
  450.     char *m_operands;
  451.     unsigned long m_opcode;
  452.     short m_opnum;
  453.     short m_codenum;
  454.     struct m68_incant *m_next;
  455. };
  456.  
  457. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  458. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  459.  
  460.  
  461. /* JF modified this to handle cases where the first part of a symbol name
  462.    looks like a register */
  463.  
  464. int
  465. m68k_reg_parse(ccp)
  466. register char **ccp;
  467. {
  468.     register char c1,
  469.         c2,
  470.         c3,
  471.         c4;
  472.     register int n = 0,
  473.         ret;
  474.  
  475.     c1=mklower(ccp[0][0]);
  476.     c2=mklower(ccp[0][1]);
  477.     c3=mklower(ccp[0][2]);
  478.     c4=mklower(ccp[0][3]);
  479.  
  480.     switch(c1) {
  481.     case 'a':
  482.         if(c2>='0' && c2<='7') {
  483.             n=2;
  484.             ret=ADDR+c2-'0';
  485.         }
  486. #ifdef m68851
  487.         else if (c2 == 'c') {
  488.             n = 2;
  489.             ret = AC;
  490.         }
  491. #endif
  492.         break;
  493. #ifdef m68851
  494.     case 'b':
  495.         if (c2 == 'a') {
  496.             if (c3 == 'd') {
  497.                 if (c4 >= '0' && c4 <= '7') {
  498.                     n = 4;
  499.                     ret = BAD + c4 - '0';
  500.                 }
  501.             }
  502.             if (c3 == 'c') {
  503.                 if (c4 >= '0' && c4 <= '7') {
  504.                     n = 4;
  505.                     ret = BAC + c4 - '0';
  506.                 }
  507.             }
  508.         }
  509.         break;
  510. #endif
  511.     case 'c':
  512. #ifdef m68851
  513.         if (c2 == 'a' && c3 == 'l') {
  514.             n = 3;
  515.             ret = CAL;
  516.         } else
  517. #endif
  518.             /* This supports both CCR and CC as the ccr reg. */
  519.         if(c2=='c' && c3=='r') {
  520.             n=3;
  521.             ret = CCR;
  522.         } else if(c2=='c') {
  523.             n=2;
  524.             ret = CCR;
  525.         } else if(c2=='a' && (c3=='a' || c3=='c') && c4=='r') {
  526.             n=4;
  527.             ret = c3=='a' ? CAAR : CACR;
  528.         }
  529. #ifdef m68851
  530.         else if (c2 == 'r' && c3 == 'p') {
  531.             n = 3;
  532.             ret = (CRP);
  533.         }
  534. #endif
  535.         break;
  536.     case 'd':
  537.         if(c2>='0' && c2<='7') {
  538.             n=2;
  539.             ret = DATA+c2-'0';
  540.         } else if(c2=='f' && c3=='c') {
  541.             n=3;
  542.             ret = DFC;
  543.         }
  544. #ifdef m68851
  545.         else if (c2 == 'r' && c3 == 'p') {
  546.             n = 3;
  547.             ret = (DRP);
  548.         }
  549. #endif
  550.         break;
  551.     case 'f':
  552.         if(c2=='p') {
  553.              if(c3>='0' && c3<='7') {
  554.                 n=3;
  555.                 ret = FPREG+c3-'0';
  556.             } else if(c3=='i') {
  557.                 n=3;
  558.                 ret = FPI;
  559.             } else if(c3=='s') {
  560.                 n= (c4 == 'r' ? 4 : 3);
  561.                 ret = FPS;
  562.             } else if(c3=='c') {
  563.                 n= (c4 == 'r' ? 4 : 3);
  564.                 ret = FPC;
  565.             }
  566.         }
  567.         break;
  568.     case 'i':
  569.         if(c2=='s' && c3=='p') {
  570.             n=3;
  571.             ret = ISP;
  572.         }
  573.         break;
  574.     case 'm':
  575.         if(c2=='s' && c3=='p') {
  576.             n=3;
  577.             ret = MSP;
  578.         }
  579.         break;
  580.     case 'p':
  581.         if(c2=='c') {
  582. #ifdef m68851
  583.             if(c3 == 's' && c4=='r') {
  584.                 n=4;
  585.                 ret = (PCSR);
  586.             } else
  587. #endif
  588.             {
  589.                 n=2;
  590.                 ret = PC;
  591.             }
  592.         }
  593. #ifdef m68851
  594.         else if (c2 == 's' && c3 == 'r') {
  595.             n = 3;
  596.             ret = (PSR);
  597.         }
  598. #endif
  599.         break;
  600.     case 's':
  601. #ifdef m68851
  602.         if (c2 == 'c' && c3 == 'c') {
  603.             n = 3;
  604.             ret = (SCC);
  605.         } else if (c2 == 'r' && c3 == 'p') {
  606.             n = 3;
  607.             ret = (SRP);
  608.         } else
  609. #endif
  610.         if(c2=='r') {
  611.             n=2;
  612.             ret = SR;
  613.         } else if(c2=='p') {
  614.             n=2;
  615.             ret = ADDR+7;
  616.         } else if(c2=='f' && c3=='c') {
  617.             n=3;
  618.             ret = SFC;
  619.         }
  620.         break;
  621. #ifdef m68851
  622.     case 't':
  623.         if(c2 == 'c') {
  624.             n=2;
  625.             ret=TC;
  626.         }
  627.         break;
  628. #endif
  629.     case 'u':
  630.         if(c2=='s' && c3=='p') {
  631.             n=3;
  632.             ret = USP;
  633.         }
  634.         break;
  635.     case 'v':
  636. #ifdef m68851
  637.         if (c2 == 'a' && c3 == 'l') {
  638.             n = 3;
  639.             ret = (VAL);
  640.         } else
  641. #endif
  642.         if(c2=='b' && c3=='r') {
  643.             n=3;
  644.             ret = VBR;
  645.         }
  646.         break;
  647.     case 'z':
  648.         if(c2=='p' && c3=='c') {
  649.             n=3;
  650.             ret = ZPC;
  651.         }
  652.         break;
  653.     default:
  654.         break;
  655.     }
  656.     if(n) {
  657.         if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
  658.             ret=FAIL;
  659.         else
  660.             ccp[0]+=n;
  661.     } else
  662.         ret = FAIL;
  663.     return ret;
  664. }
  665.  
  666. #define SKIP_WHITE()    { str++; if(*str==' ') str++;}
  667.  
  668. int
  669. m68k_ip_op(str,opP)
  670. char *str;
  671. register struct m68k_op *opP;
  672. {
  673.     char    *strend;
  674.     long    i;
  675.     char    *parse_index();
  676.  
  677.     if(*str==' ')
  678.         str++;
  679.         /* Find the end of the string */
  680.     if(!*str) {
  681.         /* Out of gas */
  682.         opP->error="Missing operand";
  683.         return FAIL;
  684.     }
  685.     for(strend=str;*strend;strend++)
  686.         ;
  687.     --strend;
  688.  
  689.         /* Guess what:  A constant.  Shar and enjoy */
  690.     if(*str=='#') {
  691.         str++;
  692.         opP->con1=add_exp(str,strend);
  693.         opP->mode=IMMED;
  694.         return OK;
  695.     }
  696.     i=m68k_reg_parse(&str);
  697.     if((i==FAIL || *str!='\0') && *str!='@@') {
  698.         char *stmp;
  699.         char *index();
  700.  
  701.         if(i!=FAIL && (*str=='/' || *str=='-')) {
  702.             opP->mode=REGLST;
  703.             return get_regs(i,str,opP);
  704.         }
  705.         if(stmp=index(str,'@@')) {
  706.             opP->con1=add_exp(str,stmp-1);
  707.             if(stmp==strend) {
  708.                 opP->mode=AINDX;
  709.                 return OK;
  710.             }
  711.             stmp++;
  712.             if(*stmp++!='(' || *strend--!=')') {
  713.                 opP->error="Malformed operand";
  714.                 return FAIL;
  715.             }
  716.             i=try_index(&stmp,opP);
  717.             opP->con2=add_exp(stmp,strend);
  718.             if(i==FAIL) opP->mode=AMIND;
  719.             else opP->mode=APODX;
  720.             return OK;
  721.         }
  722.         opP->mode=ABSL;
  723.         if(strend[-1]==':') {    /* mode ==foo:[wl] */
  724.             switch(*strend) {
  725.             case 'w':
  726.             case 'W':
  727.                 opP->isiz=2;
  728.                 break;
  729.             case 'l':
  730.             case 'L':
  731.                 opP->isiz=3;
  732.                 break;
  733.             default:
  734.                 opP->error="size spec not :w or :l";
  735.                 return FAIL;
  736.             }
  737.             strend-=2;
  738.         } else {
  739.             opP->isiz=0;
  740.         }
  741.  
  742.         opP->con1=add_exp(str,strend);
  743.         return OK;
  744.     }
  745.     opP->reg=i;
  746.     if(*str=='\0') {
  747.         if(i>=DATA+0 && i<=DATA+7)
  748.             opP->mode=DREG;
  749.         else if(i>=ADDR+0 && i<=ADDR+7)
  750.             opP->mode=AREG;
  751.         else
  752.             opP->mode=MSCR;
  753.         return OK;
  754.     }
  755.     if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) {    /* Can't indirect off non address regs */
  756.         opP->error="Invalid indirect register";
  757.         return FAIL;
  758.     }
  759.     if(*str!='@@')
  760.         abort();
  761.     str++;
  762.     switch(*str) {
  763.     case '\0':
  764.         opP->mode=AINDR;
  765.         return OK;
  766.     case '-':
  767.         opP->mode=ADEC;
  768.         return OK;
  769.     case '+':
  770.         opP->mode=AINC;
  771.         return OK;
  772.     case '(':
  773.         str++;
  774.         break;
  775.     default:
  776.         opP->error="Junk after indirect";
  777.         return FAIL;
  778.     }
  779.         /* Some kind of indexing involved.  Lets find out how bad it is */
  780.     i=try_index(&str,opP);
  781.         /* Didn't start with an index reg, maybe its offset or offset,reg */
  782.     if(i==FAIL) {
  783.         char *beg_str;
  784.  
  785.         beg_str=str;
  786.         for(i=1;i;) {
  787.             switch(*str++) {
  788.             case '\0':
  789.                 opP->error="Missing )";
  790.                 return FAIL;
  791.             case ',': i=0; break;
  792.             case '(': i++; break;
  793.             case ')': --i; break;
  794.             }
  795.         }
  796.         opP->con1=add_exp(beg_str,str-2);
  797.             /* Should be offset,reg */
  798.         if(str[-1]==',') {
  799.             i=try_index(&str,opP);
  800.             if(i==FAIL) {
  801.                 opP->error="Malformed index reg";
  802.                 return FAIL;
  803.             }
  804.         }
  805.     }
  806.         /* We've now got offset)   offset,reg)   or    reg) */
  807.  
  808.     if(*str=='\0') {
  809.         /* Th-the-thats all folks */
  810.         if(opP->reg==FAIL) opP->mode=AINDX;    /* Other form of indirect */
  811.         else if(opP->ireg==FAIL) opP->mode=AOFF;
  812.         else opP->mode=AINDX;
  813.         return OK;
  814.     }
  815.         /* Next thing had better be another @@ */
  816.     if(*str!='@@' || str[1]!='(') {
  817.         opP->error="junk after indirect";
  818.         return FAIL;
  819.     }
  820.     str+=2;
  821.     if(opP->ireg!=FAIL) {
  822.         opP->mode=APRDX;
  823.         i=try_index(&str,opP);
  824.         if(i!=FAIL) {
  825.             opP->error="Two index registers!  not allowed!";
  826.             return FAIL;
  827.         }
  828.     } else
  829.         i=try_index(&str,opP);
  830.     if(i==FAIL) {
  831.         char *beg_str;
  832.  
  833.         beg_str=str;
  834.         for(i=1;i;) {
  835.             switch(*str++) {
  836.             case '\0':
  837.                 opP->error="Missing )";
  838.                 return FAIL;
  839.             case ',': i=0; break;
  840.             case '(': i++; break;
  841.             case ')': --i; break;
  842.             }
  843.         }
  844.         opP->con2=add_exp(beg_str,str-2);
  845.         if(str[-1]==',') {
  846.             if(opP->ireg!=FAIL) {
  847.                 opP->error="Can't have two index regs";
  848.                 return FAIL;
  849.             }
  850.             i=try_index(&str,opP);
  851.             if(i==FAIL) {
  852.                 opP->error="malformed index reg";
  853.                 return FAIL;
  854.             }
  855.             opP->mode=APODX;
  856.         } else if(opP->ireg!=FAIL)
  857.             opP->mode=APRDX;
  858.         else
  859.             opP->mode=AMIND;
  860.     } else
  861.         opP->mode=APODX;
  862.     if(*str!='\0') {
  863.         opP->error="Junk after indirect";
  864.         return FAIL;
  865.     }
  866.     return OK;
  867. }
  868.  
  869. int
  870. try_index(s,opP)
  871. char **s;
  872. struct m68k_op *opP;
  873. {
  874.     register int    i;
  875.     char    *ss;
  876. #define SKIP_W()    { ss++; if(*ss==' ') ss++;}
  877.  
  878.     ss= *s;
  879.     /* SKIP_W(); */
  880.     i=m68k_reg_parse(&ss);
  881.     if(!(i>=DATA+0 && i<=ADDR+7)) {    /* if i is not DATA or ADDR reg */
  882.         *s=ss;
  883.         return FAIL;
  884.     }
  885.     opP->ireg=i;
  886.     /* SKIP_W(); */
  887.     if(*ss==')') {
  888.         opP->isiz=0;
  889.         opP->imul=1;
  890.         SKIP_W();
  891.         *s=ss;
  892.         return OK;
  893.     }
  894.     if(*ss!=':') {
  895.         opP->error="Missing : in index register";
  896.         *s=ss;
  897.         return FAIL;
  898.     }
  899.     SKIP_W();
  900.     if(mklower(*ss)=='w') opP->isiz=2;
  901.     else if(mklower(*ss)=='l') opP->isiz=3;
  902.     else {
  903.         opP->error="Size spec not :w or :l";
  904.         *s=ss;
  905.         return FAIL;
  906.     }
  907.     SKIP_W();
  908.     if(*ss==':') {
  909.         SKIP_W();
  910.         switch(*ss) {
  911.         case '1':
  912.         case '2':
  913.         case '4':
  914.         case '8':
  915.             opP->imul= *ss-'0';
  916.             break;
  917.         default:
  918.             opP->error="index multiplier not 1, 2, 4 or 8";
  919.             *s=ss;
  920.             return FAIL;
  921.         }
  922.         SKIP_W();
  923.     } else opP->imul=1;
  924.     if(*ss!=')') {
  925.         opP->error="Missing )";
  926.         *s=ss;
  927.         return FAIL;
  928.     }
  929.     SKIP_W();
  930.     *s=ss;
  931.     return OK;
  932. }
  933.  
  934. #ifdef TEST1    /* TEST1 tests m68k_ip_op(), which parses operands */
  935. main()
  936. {
  937.     char buf[128];
  938.     struct m68k_op thark;
  939.  
  940.     for(;;) {
  941.         if(!gets(buf))
  942.             break;
  943.         bzero(&thark,sizeof(thark));
  944.         if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
  945.         if(thark.error)
  946.             printf("op1 error %s in %s\n",thark.error,buf);
  947.         printf("mode %d, reg %d, ",thark.mode,thark.reg);
  948.         if(thark.b_const)
  949.             printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
  950.         printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
  951.         if(thark.b_iadd)
  952.             printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
  953.         printf("\n");
  954.     }
  955.     exit(0);
  956. }
  957.  
  958. #endif
  959.  
  960.  
  961. static struct hash_control*   op_hash = NULL;    /* handle of the OPCODE hash table
  962.                    NULL means any use before m68_ip_begin()
  963.                    will crash */
  964.  
  965.  
  966. /*
  967.  *                  m 6 8 _ i p ( )
  968.  *
  969.  * This converts a string into a 68k instruction.
  970.  * The string must be a bare single instruction in sun format
  971.  * with RMS-style 68020 indirects
  972.  *  (example:  )
  973.  *
  974.  * It provides some error messages: at most one fatal error message (which
  975.  * stops the scan) and at most one warning message for each operand.
  976.  * The 68k instruction is returned in exploded form, since we have no
  977.  * knowledge of how you parse (or evaluate) your expressions.
  978.  * We do however strip off and decode addressing modes and operation
  979.  * mnemonic.
  980.  *
  981.  * This function's value is a string. If it is not "" then an internal
  982.  * logic error was found: read this code to assign meaning to the string.
  983.  * No argument string should generate such an error string:
  984.  * it means a bug in our code, not in the user's text.
  985.  *
  986.  * You MUST have called m86_ip_begin() once and m86_ip_end() never before using
  987.  * this function.
  988.  */
  989.  
  990. /* JF this function no longer returns a useful value.  Sorry */
  991. void
  992. m68_ip (instring)
  993. char    *instring;
  994. {
  995.     register char *p;
  996.     register struct m68k_op *opP;
  997.     register struct m68_incant *opcode;
  998.     register char *s;
  999.     register int tmpreg,
  1000.         baseo,
  1001.         outro,
  1002.         nextword;
  1003.     int    siz1,
  1004.         siz2;
  1005.     char    c;
  1006.     int    losing;
  1007.     int    opsfound;
  1008.     char    *crack_operand();
  1009.     char    *atof_m68k();
  1010.     LITTLENUM_TYPE words[6];
  1011.     LITTLENUM_TYPE *wordp;
  1012.  
  1013.     if (*instring == ' ')
  1014.         instring++;            /* skip leading whitespace */
  1015.  
  1016.   /* Scan up to end of operation-code, which MUST end in end-of-string
  1017.      or exactly 1 space. */
  1018.     for (p = instring; *p != '\0'; p++)
  1019.         if (*p == ' ')
  1020.             break;
  1021.  
  1022.  
  1023.     if (p == instring) {
  1024.         the_ins.error = "No operator";
  1025.         the_ins.opcode[0] = NULL;
  1026.         /* the_ins.numo=1; */
  1027.         return;
  1028.     }
  1029.  
  1030.   /* p now points to the end of the opcode name, probably whitespace.
  1031.      make sure the name is null terminated by clobbering the whitespace,
  1032.      look it up in the hash table, then fix it back. */   
  1033.     c = *p;
  1034.     *p = '\0';
  1035.     opcode = (struct m68_incant *)hash_find (op_hash, instring);
  1036.     *p = c;
  1037.  
  1038.     if (opcode == NULL) {
  1039.         the_ins.error = "Unknown operator";
  1040.         the_ins.opcode[0] = NULL;
  1041.         /* the_ins.numo=1; */
  1042.         return;
  1043.     }
  1044.  
  1045.   /* found a legitimate opcode, start matching operands */
  1046.     for(opP= &the_ins.operands[0];*p;opP++) {
  1047.         p = crack_operand (p, opP);
  1048.         if(opP->error) {
  1049.             the_ins.error=opP->error;
  1050.             return;
  1051.         }
  1052.     }
  1053.  
  1054.     opsfound=opP- &the_ins.operands[0];
  1055.     /* This ugly hack is to support the floating pt opcodes in their standard form */
  1056.     /* Essentially, we fake a first enty of type COP#1 */
  1057.     if(opcode->m_operands[0]=='I') {
  1058.         int    n;
  1059.  
  1060.         for(n=opsfound;n>0;--n)
  1061.             the_ins.operands[n]=the_ins.operands[n-1];
  1062.  
  1063.         /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
  1064.         bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
  1065.         the_ins.operands[0].mode=MSCR;
  1066.         the_ins.operands[0].reg=COPNUM;        /* COP #1 */
  1067.         opsfound++;
  1068.     }
  1069.         /* We've got the operands.  Find an opcode that'll
  1070.            accept them */
  1071.     for(losing=0;;) {
  1072.         if(opsfound!=opcode->m_opnum)
  1073.             losing++;
  1074.         else for(s=opcode->m_operands,opP= &the_ins.operands[0];*s && !losing;s+=2,opP++) {
  1075.                 /* Warning: this switch is huge! */
  1076.                 /* I've tried to organize the cases into  this order:
  1077.                    non-alpha first, then alpha by letter.  lower-case goes directly
  1078.                    before uppercase counterpart. */
  1079.                 /* Code with multiple case ...: gets sorted by the lowest case ...
  1080.                    it belongs to.  I hope this makes sense. */
  1081.             switch(*s) {
  1082.             case '!':
  1083.                 if(opP->mode==MSCR || opP->mode==IMMED ||
  1084.  opP->mode==DREG || opP->mode==AREG || opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1085.                     losing++;
  1086.                 break;
  1087.  
  1088.             case '#':
  1089.                 if(opP->mode!=IMMED)
  1090.                      losing++;
  1091.                 else {
  1092.                     long t;
  1093.  
  1094.                     t=get_num(opP->con1,80);
  1095.                     if(s[1]=='b' && !isbyte(t))
  1096.                         losing++;
  1097.                     else if(s[1]=='w' && !isword(t))
  1098.                         losing++;
  1099.                 }
  1100.                 break;
  1101.  
  1102.             case '^':
  1103.             case 'T':
  1104.                 if(opP->mode!=IMMED)
  1105.                     losing++;
  1106.                 break;
  1107.  
  1108.             case '$':
  1109.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1110.  opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1111.                     losing++;
  1112.                 break;
  1113.  
  1114.             case '%':
  1115.                 if(opP->mode==MSCR || opP->reg==PC ||
  1116.  opP->reg==ZPC || opP->mode==REGLST)
  1117.                     losing++;
  1118.                 break;
  1119.  
  1120.  
  1121.             case '&':
  1122.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1123.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
  1124.  opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1125.                     losing++;
  1126.                 break;
  1127.  
  1128.             case '*':
  1129.                 if(opP->mode==MSCR || opP->mode==REGLST)
  1130.                     losing++;
  1131.                 break;
  1132.  
  1133.             case '+':
  1134.                 if(opP->mode!=AINC)
  1135.                     losing++;
  1136.                 break;
  1137.  
  1138.             case '-':
  1139.                 if(opP->mode!=ADEC)
  1140.                     losing++;
  1141.                 break;
  1142.  
  1143.             case '/':
  1144.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1145.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
  1146.                     losing++;
  1147.                 break;
  1148.  
  1149.             case ';':
  1150.                 if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
  1151.                     losing++;
  1152.                 break;
  1153.  
  1154.             case '?':
  1155.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1156.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
  1157.  opP->reg==ZPC || opP->mode==REGLST)
  1158.                     losing++;
  1159.                 break;
  1160.  
  1161.             case '@@':
  1162.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1163.  opP->mode==IMMED || opP->mode==REGLST)
  1164.                     losing++;
  1165.                 break;
  1166.  
  1167.             case '~':        /* For now! (JF FOO is this right?) */
  1168.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1169.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1170.                     losing++;
  1171.                 break;
  1172.  
  1173.             case 'A':
  1174.                 if(opP->mode!=AREG)
  1175.                     losing++;
  1176.                 break;
  1177.  
  1178.             case 'B':    /* FOO */
  1179.                 if(opP->mode!=ABSL)
  1180.                     losing++;
  1181.                 break;
  1182.  
  1183.             case 'C':
  1184.                 if(opP->mode!=MSCR || opP->reg!=CCR)
  1185.                     losing++;
  1186.                 break;
  1187.  
  1188.             case 'd':    /* FOO This mode is a KLUDGE!! */
  1189.                 if(opP->mode!=AOFF && (opP->mode!=ABSL ||
  1190.  opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
  1191.                     losing++;
  1192.                 break;
  1193.  
  1194.             case 'D':
  1195.                 if(opP->mode!=DREG)
  1196.                     losing++;
  1197.                 break;
  1198.  
  1199.             case 'F':
  1200.                 if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
  1201.                     losing++;
  1202.                 break;
  1203.  
  1204.             case 'I':
  1205.                 if(opP->mode!=MSCR || opP->reg<COPNUM ||
  1206.  opP->reg>=COPNUM+7)
  1207.                     losing++;
  1208.                 break;
  1209.  
  1210.             case 'J':
  1211.                 if(opP->mode!=MSCR || opP->reg<USP || opP->reg>MSP)
  1212.                     losing++;
  1213.                 break;
  1214.  
  1215.             case 'k':
  1216.                 if(opP->mode!=IMMED)
  1217.                     losing++;
  1218.                 break;
  1219.  
  1220.             case 'l':
  1221.             case 'L':
  1222.                 if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
  1223.                     if(s[1]=='8')
  1224.                         losing++;
  1225.                     else {
  1226.                         opP->mode=REGLST;
  1227.                         opP->reg=1<<(opP->reg-DATA);
  1228.                     }
  1229.                 } else if(opP->mode!=REGLST) {
  1230.                     losing++;
  1231.                 } else if(s[1]=='8' && opP->reg&0x0FFffFF)
  1232.                     losing++;
  1233.                 else if(s[1]=='3' && opP->reg&0x7000000)
  1234.                     losing++;
  1235.                 break;
  1236.  
  1237.             case 'M':
  1238.                 if(opP->mode!=IMMED)
  1239.                     losing++;
  1240.                 else {
  1241.                     long t;
  1242.  
  1243.                     t=get_num(opP->con1,80);
  1244.                     if(!issbyte(t) || isvar(opP->con1))
  1245.                         losing++;
  1246.                 }
  1247.                 break;
  1248.  
  1249.             case 'O':
  1250.                 if(opP->mode!=DREG && opP->mode!=IMMED)
  1251.                     losing++;
  1252.                 break;
  1253.  
  1254.             case 'Q':
  1255.                 if(opP->mode!=IMMED)
  1256.                     losing++;
  1257.                 else {
  1258.                     long t;
  1259.  
  1260.                     t=get_num(opP->con1,80);
  1261.                     if(t<1 || t>8 || isvar(opP->con1))
  1262.                         losing++;
  1263.                 }
  1264.                 break;
  1265.  
  1266.             case 'R':
  1267.                 if(opP->mode!=DREG && opP->mode!=AREG)
  1268.                     losing++;
  1269.                 break;
  1270.  
  1271.             case 's':
  1272.                 if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
  1273.                     losing++;
  1274.                 break;
  1275.  
  1276.             case 'S':
  1277.                 if(opP->mode!=MSCR || opP->reg!=SR)
  1278.                     losing++;
  1279.                 break;
  1280.  
  1281.             case 'U':
  1282.                 if(opP->mode!=MSCR || opP->reg!=USP)
  1283.                     losing++;
  1284.                 break;
  1285.  
  1286.             /* JF these are out of order.  We could put them
  1287.                in order if we were willing to put up with
  1288.                bunches of #ifdef m68851s in the code */
  1289. #ifdef m68851
  1290.             /* Memory addressing mode used by pflushr */
  1291.             case '|':
  1292.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1293.  opP->mode==AREG || opP->mode==REGLST)
  1294.                     losing++;
  1295.                 break;
  1296.  
  1297.             case 'f':
  1298.                 if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  1299.                     losing++;
  1300.                 break;
  1301.  
  1302.             case 'P':
  1303.                 if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
  1304.                     opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  1305.                     losing++;
  1306.                 break;
  1307.  
  1308.             case 'V':
  1309.                 if (opP->reg != VAL)
  1310.                     losing++;
  1311.                 break;
  1312.  
  1313.             case 'W':
  1314.                 if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
  1315.                     opP->reg != CRP))
  1316.                     losing++;
  1317.                 break;
  1318.  
  1319.             case 'X':
  1320.                 if (opP->mode != MSCR ||
  1321.                     (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
  1322.                      !(opP->reg >= BAC && opP->reg <= BAC+7)))
  1323.                     losing++;
  1324.                 break;
  1325.  
  1326.             case 'Y':
  1327.                 if (opP->reg != PSR)
  1328.                     losing++;
  1329.                 break;
  1330.  
  1331.             case 'Z':
  1332.                 if (opP->reg != PCSR)
  1333.                     losing++;
  1334.                 break;
  1335. #endif
  1336.             default:
  1337.                 as_fatal("Internal error:  Operand mode %c unknown",*s);
  1338.             }
  1339.         }
  1340.         if(!losing)
  1341.             break;
  1342.         opcode=opcode->m_next;
  1343.         if(!opcode) {        /* Fell off the end */
  1344.             the_ins.error="instruction/operands mismatch";
  1345.             return;
  1346.         }
  1347.         losing=0;
  1348.     }
  1349.     the_ins.args=opcode->m_operands;
  1350.     the_ins.numargs=opcode->m_opnum;
  1351.     the_ins.numo=opcode->m_codenum;
  1352.     the_ins.opcode[0]=getone(opcode);
  1353.     the_ins.opcode[1]=gettwo(opcode);
  1354.  
  1355.     for(s=the_ins.args,opP= &the_ins.operands[0];*s;s+=2,opP++) {
  1356.             /* This switch is a doozy.
  1357.                What the first step; its a big one! */
  1358.         switch(s[0]) {
  1359.  
  1360.         case '*':
  1361.         case '~':
  1362.         case '%':
  1363.         case ';':
  1364.         case '@@':
  1365.         case '!':
  1366.         case '&':
  1367.         case '$':
  1368.         case '?':
  1369.         case '/':
  1370. #ifdef m68851
  1371.         case '|':
  1372. #endif
  1373.             switch(opP->mode) {
  1374.             case IMMED:
  1375.                 tmpreg=0x3c;    /* 7.4 */
  1376.                 if(index("bwl",s[1])) nextword=get_num(opP->con1,80);
  1377.                 else nextword=nextword=get_num(opP->con1,0);
  1378.                 if(isvar(opP->con1))
  1379.                     add_fix(s[1],opP->con1,0);
  1380.                 switch(s[1]) {
  1381.                 case 'b':
  1382.                     if(!isbyte(nextword))
  1383.                         opP->error="operand out of range";
  1384.                     addword(nextword);
  1385.                     baseo=0;
  1386.                     break;
  1387.                 case 'w':
  1388.                     if(!isword(nextword))
  1389.                         opP->error="operand out of range";
  1390.                     addword(nextword);
  1391.                     baseo=0;
  1392.                     break;
  1393.                 case 'l':
  1394.                     addword(nextword>>16);
  1395.                     addword(nextword);
  1396.                     baseo=0;
  1397.                     break;
  1398.  
  1399.                 case 'f':
  1400.                     baseo=2;
  1401.                     outro=8;
  1402.                     break;
  1403.                 case 'F':
  1404.                     baseo=4;
  1405.                     outro=11;
  1406.                     break;
  1407.                 case 'x':
  1408.                     baseo=6;
  1409.                     outro=15;
  1410.                     break;
  1411.                 case 'p':
  1412.                     baseo=6;
  1413.                     outro= -1;
  1414.                     break;
  1415.                 default:
  1416.                     as_fatal("Internal error:  Can't decode %c%c",*s,s[1]);
  1417.                 }
  1418.                 if(!baseo)
  1419.                     break;
  1420.  
  1421.                 /* We gotta put out some float */
  1422.                 if(seg(opP->con1)!=SEG_BIG) {
  1423.                     int_to_gen(nextword);
  1424.                     gen_to_words(words,baseo,(long int)outro);
  1425.                     for(wordp=words;baseo--;wordp++)
  1426.                         addword(*wordp);
  1427.                     break;
  1428.                 }        /* Its BIG */
  1429.                 if(offs(opP->con1)>0) {
  1430.                     as_warn("Bignum assumed to be binary bit-pattern");
  1431.                     if(offs(opP->con1)>baseo) {
  1432.                         as_warn("Bignum too big for %c format; truncated",s[1]);
  1433.                         offs(opP->con1)=baseo;
  1434.                     }
  1435.                     baseo-=offs(opP->con1);
  1436.                     for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
  1437.                         addword(*wordp);
  1438.                     while(baseo--)
  1439.                         addword(0);
  1440.                     break;
  1441.                 }
  1442.                 gen_to_words(words,baseo,(long int)outro);
  1443.                 for(wordp=words;baseo--;wordp++)
  1444.                     addword(*wordp);
  1445.                 break;
  1446.             case DREG:
  1447.                 tmpreg=opP->reg-DATA; /* 0.dreg */
  1448.                 break;
  1449.             case AREG:
  1450.                 tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
  1451.                 break;
  1452.             case AINDR:
  1453.                 tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
  1454.                 break;
  1455.             case ADEC:
  1456.                 tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
  1457.                 break;
  1458.             case AINC:
  1459.                 tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
  1460.                 break;
  1461.             case AOFF:
  1462.                 if(opP->reg==PC)
  1463.                     tmpreg=0x3A; /* 7.2 */
  1464.                 else
  1465.                     tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
  1466.                 nextword=get_num(opP->con1,80);
  1467.                 /* Force into index mode.  Hope this works */
  1468.                 if(!issword(nextword)) {
  1469.                     if(opP->reg==PC)
  1470.                         tmpreg=0x3B;    /* 7.3 */
  1471.                     else
  1472.                         tmpreg=0x30+opP->reg-ADDR;    /* 6.areg */
  1473.                     /* addword(0x0171); */
  1474. /* 171 seems to be wrong, and I can't find the 68020 manual, so we'll try 170
  1475.    (which is what the Sun asm seems to generate */
  1476.                     addword(0x0170);
  1477.                     if(isvar(opP->con1))
  1478.                         add_fix('l',opP->con1,0);
  1479.                     addword(nextword>>16);
  1480.                     /* addword(nextword); */
  1481.                 } else if(isvar(opP->con1)) {
  1482.                     if(!flagseen['l']) {
  1483.                         add_fix('w',opP->con1,0);
  1484.                     } else {
  1485.                         tmpreg=0x30+opP->reg-ADDR;
  1486.                         addword(0x0170);
  1487.                         add_fix('l',opP->con1,0);
  1488.                         addword(nextword>>16);
  1489.                     }
  1490.                 }
  1491.                 addword(nextword);
  1492.                 break;
  1493.             case AINDX:
  1494.             case APODX:
  1495.             case AMIND:
  1496.             case APRDX:
  1497.                 nextword=0;
  1498.                 baseo=get_num(opP->con1,80);
  1499.                 outro=get_num(opP->con2,80);
  1500.                     /* Figure out the 'addressing mode' */
  1501.                     /* Also turn on the BASE_DISABLE bit, if needed */
  1502.                 if(opP->reg==PC || opP->reg==ZPC) {
  1503.                     tmpreg=0x3b; /* 7.3 */
  1504.                     if(opP->reg==ZPC)
  1505.                         nextword|=0x80;
  1506.                 } else if(opP->reg==FAIL) {
  1507.                     nextword|=0x80;
  1508.                     tmpreg=0x30;    /* 6.garbage */
  1509.                 } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
  1510.  
  1511.                 siz1= (opP->con1) ? opP->con1->e_siz : 0;
  1512.                 siz2= (opP->con2) ? opP->con2->e_siz : 0;
  1513.  
  1514.                     /* Index register stuff */
  1515.                 if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
  1516.                     nextword|=(opP->ireg-DATA)<<12;
  1517.  
  1518.                     if(opP->isiz==0 || opP->isiz==3)
  1519.                         nextword|=0x800;
  1520.                     switch(opP->imul) {
  1521.                     case 1: break;
  1522.                     case 2: nextword|=0x200; break;
  1523.                     case 4: nextword|=0x400; break;
  1524.                     case 8: nextword|=0x600; break;
  1525.                     default: abort();
  1526.                     }
  1527.                         /* IF its simple, GET US OUT OF HERE! */
  1528.                         /* Must be INDEX, with an index register.  Address register
  1529.                            cannot be ZERO-PC, and either :b was forced, or we know it'll fit */
  1530.                     if(opP->mode==AINDX &&
  1531.  opP->reg!=FAIL && opP->reg!=ZPC && (siz1==1 || (issbyte(baseo) &&
  1532.  !isvar(opP->con1)))) {
  1533.                         nextword +=baseo&0xff;
  1534.                         addword(nextword);
  1535.                         if(isvar(opP->con1))
  1536.                             add_fix('B',opP->con1,0);
  1537.                         break;
  1538.                     }
  1539.                 } else
  1540.                     nextword|=0x40;    /* No index reg */
  1541.                 
  1542.                     /* It aint simple */
  1543.                 nextword|=0x100;
  1544.                     /* If the guy specified a width, we assume that
  1545.                        it is wide enough.  Maybe it isn't.  Ifso, we lose
  1546.                      */
  1547.                 switch(siz1) {
  1548.                 case 0:
  1549.                     if(isvar(opP->con1) || !issword(baseo)) {
  1550.                         siz1=3;
  1551.                         nextword|=0x30;
  1552.                     } else if(baseo==0)
  1553.                         nextword|=0x10;
  1554.                     else {    
  1555.                         nextword|=0x20;
  1556.                         siz1=2;
  1557.                     }
  1558.                     break;
  1559.                 case 1:
  1560.                     as_warn("Byte dispacement won't work.  Defaulting to :w");
  1561.                 case 2:
  1562.                     nextword|=0x20;
  1563.                     break;
  1564.                 case 3:
  1565.                     nextword|=0x30;
  1566.                     break;
  1567.                 }
  1568.  
  1569.                     /* Figure out innner displacement stuff */
  1570.                 if(opP->mode!=AINDX) {
  1571.                     switch(siz2) {
  1572.                     case 0:
  1573.                         if(isvar(opP->con2) || !issword(outro)) {
  1574.                             siz2=3;
  1575.                             nextword|=0x3;
  1576.                         } else if(outro==0)
  1577.                             nextword|=0x1;
  1578.                         else {    
  1579.                             nextword|=0x2;
  1580.                             siz2=2;
  1581.                         }
  1582.                         break;
  1583.                     case 1:
  1584.                         as_warn("Byte dispacement won't work.  Defaulting to :w");
  1585.                     case 2:
  1586.                         nextword|=0x2;
  1587.                         break;
  1588.                     case 3:
  1589.                         nextword|=0x3;
  1590.                         break;
  1591.                     }
  1592.                     if(opP->mode==APODX) nextword|=0x04;
  1593.                     else if(opP->mode==AMIND) nextword|=0x40;
  1594.                 }
  1595.                 addword(nextword);
  1596.  
  1597.                 if(isvar(opP->con1))
  1598.                     add_fix(siz1==3 ? 'l' : 'w',opP->con1,0);
  1599.                 if(siz1==3)
  1600.                     addword(baseo>>16);
  1601.                 if(siz1)
  1602.                     addword(baseo);
  1603.  
  1604.                 if(isvar(opP->con2))
  1605.                     add_fix(siz2==3 ? 'l' : 'w',opP->con2,0);
  1606.                 if(siz2==3)
  1607.                     addword(outro>>16);
  1608.                 if(siz2)
  1609.                     addword(outro);
  1610.  
  1611.                 break;
  1612.  
  1613.             case ABSL:
  1614.                 nextword=get_num(opP->con1,80);
  1615.                 switch(opP->isiz) {
  1616.                 case 0:
  1617.                     if(!isvar(opP->con1) && issword(offs(opP->con1))) {
  1618.                         tmpreg=0x38; /* 7.0 */
  1619.                         addword(nextword);
  1620.                         break;
  1621.                     }
  1622.                     /* Don't generate pc relative code
  1623.                        on 68010 and 68000 */
  1624.                     if(isvar(opP->con1) &&
  1625.                        !subs(opP->con1) &&
  1626.                        seg(opP->con1)==SEG_TEXT &&
  1627.                         now_seg==SEG_TEXT &&
  1628.                        flagseen['m']==0 &&
  1629.                         !index("~%&$?", s[0])) {
  1630.                         tmpreg=0x3A; /* 7.2 */
  1631.                         add_frag(adds(opP->con1),
  1632.                              offs(opP->con1),
  1633.                              TAB(PCREL,SZ_UNDEF));
  1634.                         break;
  1635.                     }
  1636.                 case 3:        /* Fall through into long */
  1637.                     if(isvar(opP->con1))
  1638.                         add_fix('l',opP->con1,0);
  1639.  
  1640.                     tmpreg=0x39;    /* 7.1 mode */
  1641.                     addword(nextword>>16);
  1642.                     addword(nextword);
  1643.                     break;
  1644.  
  1645.                 case 2:        /* Word */
  1646.                     if(isvar(opP->con1))
  1647.                         add_fix('w',opP->con1,0);
  1648.  
  1649.                     tmpreg=0x38;    /* 7.0 mode */
  1650.                     addword(nextword);
  1651.                     break;
  1652.                 }
  1653.                 break;
  1654.             case MSCR:
  1655.             default:
  1656.                 as_warn("unknown/incorrect operand");
  1657.                 /* abort(); */
  1658.             }
  1659.             install_gen_operand(s[1],tmpreg);
  1660.             break;
  1661.  
  1662.         case '#':
  1663.         case '^':
  1664.             switch(s[1]) {    /* JF: I hate floating point! */
  1665.             case 'j':
  1666.                 tmpreg=70;
  1667.                 break;
  1668.             case '8':
  1669.                 tmpreg=20;
  1670.                 break;
  1671.             case 'C':
  1672.                 tmpreg=50;
  1673.                 break;
  1674.             case '3':
  1675.             default:
  1676.                 tmpreg=80;
  1677.                 break;
  1678.             }
  1679.             tmpreg=get_num(opP->con1,tmpreg);
  1680.             if(isvar(opP->con1))
  1681.                 add_fix(s[1],opP->con1,0);
  1682.             switch(s[1]) {
  1683.             case 'b':    /* Danger:  These do no check for
  1684.                        certain types of overflow.
  1685.                        user beware! */
  1686.                 if(!isbyte(tmpreg))
  1687.                     opP->error="out of range";
  1688.                 insop(tmpreg);
  1689.                 if(isvar(opP->con1))
  1690.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1691.                 break;
  1692.             case 'w':
  1693.                 if(!isword(tmpreg))
  1694.                     opP->error="out of range";
  1695.                 insop(tmpreg);
  1696.                 if(isvar(opP->con1))
  1697.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1698.                 break;
  1699.             case 'l':
  1700.                 insop(tmpreg);        /* Because of the way insop works, we put these two out backwards */
  1701.                 insop(tmpreg>>16);
  1702.                 if(isvar(opP->con1))
  1703.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1704.                 break;
  1705.             case '3':
  1706.                 tmpreg&=0xFF;
  1707.             case '8':
  1708.             case 'C':
  1709.                 install_operand(s[1],tmpreg);
  1710.                 break;
  1711.             default:
  1712.                 as_fatal("Internal error:  Unknown mode #%c",s[1]);
  1713.             }
  1714.             break;
  1715.  
  1716.         case '+':
  1717.         case '-':
  1718.         case 'A':
  1719.             install_operand(s[1],opP->reg-ADDR);
  1720.             break;
  1721.  
  1722.         case 'B':
  1723.             tmpreg=get_num(opP->con1,80);
  1724.             switch(s[1]) {
  1725.             case 'g':
  1726.                 if(opP->con1->e_siz) {    /* Deal with fixed size stuff by hand */
  1727.                     switch(opP->con1->e_siz) {
  1728.                     case 1:
  1729.                         add_fix('b',opP->con1,1);
  1730.                         break;
  1731.                     case 2:
  1732.                         add_fix('w',opP->con1,1);
  1733.                         addword(0);
  1734.                         break;
  1735.                     case 3:
  1736.                         add_fix('l',opP->con1,1);
  1737.                         addword(0);
  1738.                         addword(0);
  1739.                         break;
  1740.                     default:
  1741.                         as_fatal("Bad size for expression %d",opP->con1->e_siz);
  1742.                     }
  1743.                 } else if(subs(opP->con1)) {
  1744.                         /* We can't relax it */
  1745.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1746.                     add_fix('l',opP->con1,1);
  1747.                     addword(0);
  1748.                     addword(0);
  1749.                 } else if(adds(opP->con1)) {
  1750.                     if (flagseen['m'] && 
  1751.                         (the_ins.opcode[0] >= 0x6200) &&
  1752.                         (the_ins.opcode[0] <= 0x6f00)) {
  1753.                       add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
  1754.                         } else {
  1755.                     add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
  1756.                         }
  1757.                 } else {
  1758.                     /* JF:  This is the WRONG thing to do
  1759.                     add_frag((symbolS *)0,offs(opP->con1),TAB(BRANCH,BYTE)); */
  1760.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1761.                     add_fix('l',opP->con1,1);
  1762.                     addword(0);
  1763.                     addword(4);
  1764.                 }
  1765.                 break;
  1766.             case 'w':
  1767.                 if(isvar(opP->con1)) {
  1768.                     /* check for DBcc instruction */
  1769.                                     if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8){
  1770.                                             /* size varies if patch */
  1771.                                             /* needed for long form */
  1772.                                             add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
  1773.                                             break;
  1774.                                         }
  1775.                                         
  1776.                         /* Don't ask! */
  1777.                     opP->con1->e_exp.X_add_number+=2;
  1778.                     add_fix('w',opP->con1,1);
  1779.                 }
  1780.                 addword(0);
  1781.                 break;
  1782.             case 'c':
  1783.                 if(opP->con1->e_siz) {
  1784.                     switch(opP->con1->e_siz) {
  1785.                     case 2:
  1786.                         add_fix('w',opP->con1,1)
  1787.                         addword(0);
  1788.                         break;
  1789.                     case 3:
  1790.                         the_ins.opcode[the_ins.numo-1]|=0x40;
  1791.                         add_fix('l',opP->con1,1);
  1792.                         addword(0);
  1793.                         addword(0);
  1794.                         break;
  1795.                     default:
  1796.                         as_warn("Bad size for offset, must be word or long");
  1797.                         break;
  1798.                     }
  1799.                 } else if(subs(opP->con1)) {
  1800.                     add_fix('l',opP->con1,1);
  1801.                     add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
  1802.                 } else if(adds(opP->con1)) {
  1803.                     add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
  1804.                 } else {
  1805.                     /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  1806.                     the_ins.opcode[the_ins.numo-1]|=0x40;
  1807.                     add_fix('l',opP->con1,1);
  1808.                     addword(0);
  1809.                     addword(4);
  1810.                 }
  1811.                 break;
  1812.             default:
  1813.                 as_fatal("Internal error:  operand type B%c unknown",s[1]);
  1814.             }
  1815.             break;
  1816.  
  1817.         case 'C':        /* Ignore it */
  1818.             break;
  1819.  
  1820.         case 'd':        /* JF this is a kludge */
  1821.             if(opP->mode==AOFF) {
  1822.                 install_operand('s',opP->reg-ADDR);
  1823.             } else {
  1824.                 char *tmpP;
  1825.  
  1826.                 tmpP=opP->con1->e_end-2;
  1827.                 opP->con1->e_beg++;
  1828.                 opP->con1->e_end-=4;    /* point to the , */
  1829.                 baseo=m68k_reg_parse(&tmpP);
  1830.                 if(baseo<ADDR+0 || baseo>ADDR+7) {
  1831.                     as_warn("Unknown address reg, using A0");
  1832.                     baseo=0;
  1833.                 } else baseo-=ADDR;
  1834.                 install_operand('s',baseo);
  1835.             }
  1836.             tmpreg=get_num(opP->con1,80);
  1837.             if(!issword(tmpreg)) {
  1838.                 as_warn("Expression out of range, using 0");
  1839.                 tmpreg=0;
  1840.             }
  1841.             addword(tmpreg);
  1842.             break;
  1843.  
  1844.         case 'D':
  1845.             install_operand(s[1],opP->reg-DATA);
  1846.             break;
  1847.  
  1848.         case 'F':
  1849.             install_operand(s[1],opP->reg-FPREG);
  1850.             break;
  1851.  
  1852.         case 'I':
  1853.             tmpreg=1+opP->reg-COPNUM;
  1854.             if(tmpreg==8)
  1855.                 tmpreg=0;
  1856.             install_operand(s[1],tmpreg);
  1857.             break;
  1858.  
  1859.         case 'J':        /* JF foo */
  1860.             switch(opP->reg) {
  1861.             case SFC:
  1862.                 tmpreg=0;
  1863.                 break;
  1864.             case DFC:
  1865.                 tmpreg=0x001;
  1866.                 break;
  1867.             case CACR:
  1868.                 tmpreg=0x002;
  1869.                 break;
  1870.             case USP:
  1871.                 tmpreg=0x800;
  1872.                 break;
  1873.             case VBR:
  1874.                 tmpreg=0x801;
  1875.                 break;
  1876.             case CAAR:
  1877.                 tmpreg=0x802;
  1878.                 break;
  1879.             case MSP:
  1880.                 tmpreg=0x803;
  1881.                 break;
  1882.             case ISP:
  1883.                 tmpreg=0x804;
  1884.                 break;
  1885.             default:
  1886.                 abort();
  1887.             }
  1888.             install_operand(s[1],tmpreg);
  1889.             break;
  1890.  
  1891.         case 'k':
  1892.             tmpreg=get_num(opP->con1,55);
  1893.             install_operand(s[1],tmpreg&0x7f);
  1894.             break;
  1895.  
  1896.         case 'l':
  1897.             tmpreg=opP->reg;
  1898.             if(s[1]=='w') {
  1899.                 if(tmpreg&0x7FF0000)
  1900.                     as_warn("Floating point register in register list");
  1901.                 insop(reverse_16_bits(tmpreg));
  1902.             } else {
  1903.                 if(tmpreg&0x700FFFF)
  1904.                     as_warn("Wrong register in floating-point reglist");
  1905.                 install_operand(s[1],reverse_8_bits(tmpreg>>16));
  1906.             }
  1907.             break;
  1908.  
  1909.         case 'L':
  1910.             tmpreg=opP->reg;
  1911.             if(s[1]=='w') {
  1912.                 if(tmpreg&0x7FF0000)
  1913.                     as_warn("Floating point register in register list");
  1914.                 insop(tmpreg);
  1915.             } else if(s[1]=='8') {
  1916.                 if(tmpreg&0x0FFFFFF)
  1917.                     as_warn("incorrect register in reglist");
  1918.                 install_operand(s[1],tmpreg>>24);
  1919.             } else {
  1920.                 if(tmpreg&0x700FFFF)
  1921.                     as_warn("wrong register in floating-point reglist");
  1922.                 else
  1923.                     install_operand(s[1],tmpreg>>16);
  1924.             }
  1925.             break;
  1926.  
  1927.         case 'M':
  1928.             install_operand(s[1],get_num(opP->con1,60));
  1929.             break;
  1930.  
  1931.         case 'O':
  1932.             tmpreg= (opP->mode==DREG)
  1933.                 ? 0x20+opP->reg-DATA
  1934.                 : (get_num(opP->con1,40)&0x1F);
  1935.             install_operand(s[1],tmpreg);
  1936.             break;
  1937.  
  1938.         case 'Q':
  1939.             tmpreg=get_num(opP->con1,10);
  1940.             if(tmpreg==8)
  1941.                 tmpreg=0;
  1942.             install_operand(s[1],tmpreg);
  1943.             break;
  1944.  
  1945.         case 'R':
  1946.             /* This depends on the fact that ADDR registers are
  1947.                eight more than their corresponding DATA regs, so
  1948.                the result will have the ADDR_REG bit set */
  1949.             install_operand(s[1],opP->reg-DATA);
  1950.             break;
  1951.  
  1952.         case 's':
  1953.             if(opP->reg==FPI) tmpreg=0x1;
  1954.             else if(opP->reg==FPS) tmpreg=0x2;
  1955.             else if(opP->reg==FPC) tmpreg=0x4;
  1956.             else abort();
  1957.             install_operand(s[1],tmpreg);
  1958.             break;
  1959.  
  1960.         case 'S':    /* Ignore it */
  1961.             break;
  1962.  
  1963.         case 'T':
  1964.             install_operand(s[1],get_num(opP->con1,30));
  1965.             break;
  1966.  
  1967.         case 'U':    /* Ignore it */
  1968.             break;
  1969.  
  1970. #ifdef m68851
  1971.             /* JF: These are out of order, I fear. */
  1972.         case 'f':
  1973.             switch (opP->reg) {
  1974.             case SFC:
  1975.                 tmpreg=0;
  1976.                 break;
  1977.             case DFC:
  1978.                 tmpreg=1;
  1979.                 break;
  1980.             default:
  1981.                 abort();
  1982.             }
  1983.             install_operand(s[1],tmpreg);
  1984.             break;
  1985.  
  1986.         case 'P':
  1987.             switch(opP->reg) {
  1988.             case TC:
  1989.                 tmpreg=0;
  1990.                 break;
  1991.             case CAL:
  1992.                 tmpreg=4;
  1993.                 break;
  1994.             case VAL:
  1995.                 tmpreg=5;
  1996.                 break;
  1997.             case SCC:
  1998.                 tmpreg=6;
  1999.                 break;
  2000.             case AC:
  2001.                 tmpreg=7;
  2002.                 break;
  2003.             default:
  2004.                 abort();
  2005.             }
  2006.             install_operand(s[1],tmpreg);
  2007.             break;
  2008.  
  2009.         case 'V':
  2010.             if (opP->reg == VAL)
  2011.                 break;
  2012.             abort();
  2013.  
  2014.         case 'W':
  2015.             switch(opP->reg) {
  2016.  
  2017.             case DRP:
  2018.                 tmpreg=1;
  2019.                 break;
  2020.             case SRP:
  2021.                 tmpreg=2;
  2022.                 break;
  2023.             case CRP:
  2024.                 tmpreg=3;
  2025.                 break;
  2026.             default:
  2027.                 abort();
  2028.             }
  2029.             install_operand(s[1],tmpreg);
  2030.             break;
  2031.  
  2032.         case 'X':
  2033.             switch (opP->reg) {
  2034.             case BAD: case BAD+1: case BAD+2: case BAD+3:
  2035.             case BAD+4: case BAD+5: case BAD+6: case BAD+7:
  2036.                 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  2037.                 break;
  2038.  
  2039.             case BAC: case BAC+1: case BAC+2: case BAC+3:
  2040.             case BAC+4: case BAC+5: case BAC+6: case BAC+7:
  2041.                 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  2042.                 break;
  2043.  
  2044.             default:
  2045.                 abort();
  2046.             }
  2047.             install_operand(s[1], tmpreg);
  2048.             break;
  2049.         case 'Y':
  2050.             if (opP->reg == PSR)
  2051.                 break;
  2052.             abort();
  2053.  
  2054.         case 'Z':
  2055.             if (opP->reg == PCSR)
  2056.                 break;
  2057.             abort;
  2058. #endif /* m68851 */
  2059.         default:
  2060.             as_fatal("Internal error:  Operand type %c unknown",s[0]);
  2061.         }
  2062.     }
  2063.     /* By the time whe get here (FINALLY) the_ins contains the complete
  2064.        instruction, ready to be emitted. . . */
  2065. }
  2066.  
  2067. int
  2068. get_regs(i,str,opP)
  2069. struct m68k_op *opP;
  2070. char *str;
  2071. {
  2072.     /*                 26, 25, 24, 23-16,  15-8, 0-7 */
  2073.     /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  2074.     unsigned long int cur_regs = 0;
  2075.     int    reg1,
  2076.         reg2;
  2077.  
  2078. #define ADD_REG(x)    {     if(x==FPI) cur_regs|=(1<<24);\
  2079.              else if(x==FPS) cur_regs|=(1<<25);\
  2080.              else if(x==FPC) cur_regs|=(1<<26);\
  2081.              else cur_regs|=(1<<(x-1));  }
  2082.  
  2083.     reg1=i;
  2084.     for(;;) {
  2085.         if(*str=='/') {
  2086.             ADD_REG(reg1);
  2087.             str++;
  2088.         } else if(*str=='-') {
  2089.             str++;
  2090.             reg2=m68k_reg_parse(&str);
  2091.             if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
  2092.                 opP->error="unknown register in register list";
  2093.                 return FAIL;
  2094.             }
  2095.             while(reg1<=reg2) {
  2096.                 ADD_REG(reg1);
  2097.                 reg1++;
  2098.             }
  2099.             if(*str=='\0')
  2100.                 break;
  2101.         } else if(*str=='\0') {
  2102.             ADD_REG(reg1);
  2103.             break;
  2104.         } else {
  2105.             opP->error="unknow character in register list";
  2106.             return FAIL;
  2107.         }
  2108. /* DJA -- Bug Fix.  Did't handle d1-d2/a1 until the following instruction was added */
  2109.         if (*str=='/')
  2110.           str ++;
  2111.         reg1=m68k_reg_parse(&str);
  2112.         if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
  2113.             opP->error="unknown register in register list";
  2114.             return FAIL;
  2115.         }
  2116.     }
  2117.     opP->reg=cur_regs;
  2118.     return OK;
  2119. }
  2120.  
  2121. int
  2122. reverse_16_bits(in)
  2123. int in;
  2124. {
  2125.     int out=0;
  2126.     int n;
  2127.  
  2128.     static int mask[16] = {
  2129. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2130. 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
  2131.     };
  2132.     for(n=0;n<16;n++) {
  2133.         if(in&mask[n])
  2134.             out|=mask[15-n];
  2135.     }
  2136.     return out;
  2137. }
  2138.  
  2139. int
  2140. reverse_8_bits(in)
  2141. int in;
  2142. {
  2143.     int out=0;
  2144.     int n;
  2145.  
  2146.     static int mask[8] = {
  2147. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2148.     };
  2149.  
  2150.     for(n=0;n<8;n++) {
  2151.         if(in&mask[n])
  2152.             out|=mask[7-n];
  2153.     }
  2154.     return out;
  2155. }
  2156.     
  2157. void
  2158. install_operand(mode,val)
  2159. int mode;
  2160. int val;
  2161. {
  2162.     switch(mode) {
  2163.     case 's':
  2164.         the_ins.opcode[0]|=val & 0xFF;    /* JF FF is for M kludge */
  2165.         break;
  2166.     case 'd':
  2167.         the_ins.opcode[0]|=val<<9;
  2168.         break;
  2169.     case '1':
  2170.         the_ins.opcode[1]|=val<<12;
  2171.         break;
  2172.     case '2':
  2173.         the_ins.opcode[1]|=val<<6;
  2174.         break;
  2175.     case '3':
  2176.         the_ins.opcode[1]|=val;
  2177.         break;
  2178.     case '4':
  2179.         the_ins.opcode[2]|=val<<12;
  2180.         break;
  2181.     case '5':
  2182.         the_ins.opcode[2]|=val<<6;
  2183.         break;
  2184.     case '6':
  2185.             /* DANGER!  This is a hack to force cas2l and cas2w cmds
  2186.                to be three words long! */
  2187.         the_ins.numo++;
  2188.         the_ins.opcode[2]|=val;
  2189.         break;
  2190.     case '7':
  2191.         the_ins.opcode[1]|=val<<7;
  2192.         break;
  2193.     case '8':
  2194.         the_ins.opcode[1]|=val<<10;
  2195.         break;
  2196. #ifdef m68851
  2197.     case '9':
  2198.         the_ins.opcode[1]|=val<<5;
  2199.         break;
  2200. #endif
  2201.         
  2202.     case 't':
  2203.         the_ins.opcode[1]|=(val<<10)|(val<<7);
  2204.         break;
  2205.     case 'D':
  2206.         the_ins.opcode[1]|=(val<<12)|val;
  2207.         break;
  2208.     case 'g':
  2209.         the_ins.opcode[0]|=val=0xff;
  2210.         break;
  2211.     case 'i':
  2212.         the_ins.opcode[0]|=val<<9;
  2213.         break;
  2214.     case 'C':
  2215.         the_ins.opcode[1]|=val;
  2216.         break;
  2217.     case 'j':
  2218.         the_ins.opcode[1]|=val;
  2219.         the_ins.numo++;        /* What a hack */
  2220.         break;
  2221.     case 'k':
  2222.         the_ins.opcode[1]|=val<<4;
  2223.         break;
  2224.     case 'b':
  2225.     case 'w':
  2226.     case 'l':
  2227.         break;
  2228.     case 'c':
  2229.     default:
  2230.         abort();
  2231.     }
  2232. }
  2233.  
  2234. void
  2235. install_gen_operand(mode,val)
  2236. int mode;
  2237. int val;
  2238. {
  2239.     switch(mode) {
  2240.     case 's':
  2241.         the_ins.opcode[0]|=val;
  2242.         break;
  2243.     case 'd':
  2244.             /* This is a kludge!!! */
  2245.         the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
  2246.         break;
  2247.     case 'b':
  2248.     case 'w':
  2249.     case 'l':
  2250.     case 'f':
  2251.     case 'F':
  2252.     case 'x':
  2253.     case 'p':
  2254.         the_ins.opcode[0]|=val;
  2255.         break;
  2256.         /* more stuff goes here */
  2257.     default:
  2258.         abort();
  2259.     }
  2260. }
  2261.  
  2262. char *
  2263. crack_operand(str,opP)
  2264. register char *str;
  2265. register struct m68k_op *opP;
  2266. {
  2267.     register int parens;
  2268.     register int c;
  2269.     register char *beg_str;
  2270.  
  2271.     if(!str) {
  2272.         return str;
  2273.     }
  2274.     beg_str=str;
  2275.     for(parens=0;*str && (parens>0 || notend(str));str++) {
  2276.         if(*str=='(') parens++;
  2277.         else if(*str==')') {
  2278.             if(!parens) {        /* ERROR */
  2279.                 opP->error="Extra )";
  2280.                 return str;
  2281.             }
  2282.             --parens;
  2283.         }
  2284.     }
  2285.     if(!*str && parens) {        /* ERROR */
  2286.         opP->error="Missing )";
  2287.         return str;
  2288.     }
  2289.     c= *str;
  2290.     *str='\0';
  2291.     if(m68k_ip_op(beg_str,opP)==FAIL) {
  2292.         *str=c;
  2293.         return str;
  2294.     }
  2295.     *str=c;
  2296.     if(c=='}')
  2297.         c= *++str;        /* JF bitfield hack */
  2298.     if(c) {
  2299.          c= *++str;
  2300.         if(!c)
  2301.             as_warn("Missing operand");
  2302.     }
  2303.     return str;
  2304. }
  2305.  
  2306. /* See the comment up above where the #define notend(... is */
  2307. #if 0
  2308. notend(s)
  2309. char *s;
  2310. {
  2311.     if(*s==',') return 0;
  2312.     if(*s=='{' || *s=='}')
  2313.         return 0;
  2314.     if(*s!=':') return 1;
  2315.         /* This kludge here is for the division cmd, which is a kludge */
  2316.     if(index("aAdD#",s[1])) return 0;
  2317.     return 1;
  2318. }
  2319. #endif
  2320.  
  2321. /* This is the guts of the machine-dependent assembler.  STR points to a
  2322.    machine dependent instruction.  This funciton is supposed to emit
  2323.    the frags/bytes it assembles to.
  2324.  */
  2325. void
  2326. md_assemble(str)
  2327. char *str;
  2328. {
  2329.     char *er;
  2330.     short    *fromP;
  2331.     char    *toP;
  2332.     int    m,n;
  2333.     char    *to_beg_P;
  2334.     int    shorts_this_frag;
  2335.  
  2336.     bzero((char *)(&the_ins),sizeof(the_ins));    /* JF for paranoia sake */
  2337.     m68_ip(str);
  2338.     er=the_ins.error;
  2339.     if(!er) {
  2340.         for(n=the_ins.numargs;n;--n)
  2341.             if(the_ins.operands[n].error) {
  2342.                 er=the_ins.operands[n].error;
  2343.                 break;
  2344.             }
  2345.     }
  2346.     if(er) {
  2347.         as_warn("\"%s\" -- Statement '%s' ignored",er,str);
  2348.         return;
  2349.     }
  2350.  
  2351.     if(the_ins.nfrag==0) {    /* No frag hacking involved; just put it out */
  2352.         toP=frag_more(2*the_ins.numo);
  2353.         fromP= &the_ins.opcode[0];
  2354.         for(m=the_ins.numo;m;--m) {
  2355.             md_number_to_chars(toP,(long)(*fromP),2);
  2356.             toP+=2;
  2357.             fromP++;
  2358.         }
  2359.             /* put out symbol-dependent info */
  2360.         for(m=0;m<the_ins.nrel;m++) {
  2361.             switch(the_ins.reloc[m].wid) {
  2362.             case 'B':
  2363.                 n=1;
  2364.                 break;
  2365.             case 'b':
  2366.                 n=1;
  2367.                 break;
  2368.             case 'w':
  2369.                 n=2;
  2370.                 break;
  2371.             case 'l':
  2372.                 n=4;
  2373.                 break;
  2374.             default:
  2375.                 as_fatal("confusing width %c",the_ins.reloc[m].wid);
  2376.             }
  2377.  
  2378.             fix_new(frag_now,
  2379.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2380.                 n,
  2381.                 the_ins.reloc[m].add,
  2382.                 the_ins.reloc[m].sub,
  2383.                 the_ins.reloc[m].off,
  2384.                 the_ins.reloc[m].pcrel);
  2385.         }
  2386.         return;
  2387.     }
  2388.  
  2389.         /* There's some frag hacking */
  2390.     for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
  2391.         int wid;
  2392.  
  2393.         if(n==0) wid=2*the_ins.fragb[n].fragoff;
  2394.         else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2395.         toP=frag_more(wid);
  2396.         to_beg_P=toP;
  2397.         shorts_this_frag=0;
  2398.         for(m=wid/2;m;--m) {
  2399.             md_number_to_chars(toP,(long)(*fromP),2);
  2400.             toP+=2;
  2401.             fromP++;
  2402.             shorts_this_frag++;
  2403.         }
  2404.         for(m=0;m<the_ins.nrel;m++) {
  2405.             if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
  2406.                 the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
  2407.                 break;
  2408.             }
  2409.             wid=the_ins.reloc[m].wid;
  2410.             if(wid==0)
  2411.                 continue;
  2412.             the_ins.reloc[m].wid=0;
  2413.             wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2414.  
  2415.             fix_new(frag_now,
  2416.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2417.                 wid,
  2418.                 the_ins.reloc[m].add,
  2419.                 the_ins.reloc[m].sub,
  2420.                 the_ins.reloc[m].off,
  2421.                 the_ins.reloc[m].pcrel);
  2422.         }
  2423.         know(the_ins.fragb[n].fadd);
  2424.                 (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
  2425.  the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
  2426.     }
  2427.     n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2428.     shorts_this_frag=0;
  2429.     if(n) {
  2430.         toP=frag_more(n*sizeof(short));
  2431.         while(n--) {
  2432.             md_number_to_chars(toP,(long)(*fromP),2);
  2433.             toP+=2;
  2434.             fromP++;
  2435.             shorts_this_frag++;
  2436.         }
  2437.     }
  2438.     for(m=0;m<the_ins.nrel;m++) {
  2439.         int wid;
  2440.  
  2441.         wid=the_ins.reloc[m].wid;
  2442.         if(wid==0)
  2443.             continue;
  2444.         the_ins.reloc[m].wid=0;
  2445.         wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2446.  
  2447.         fix_new(frag_now,
  2448.             (the_ins.reloc[m].n + toP-frag_now->fr_literal)-/* the_ins.numo */ shorts_this_frag*2,
  2449.             wid,
  2450.             the_ins.reloc[m].add,
  2451.             the_ins.reloc[m].sub,
  2452.             the_ins.reloc[m].off,
  2453.             the_ins.reloc[m].pcrel);
  2454.     }
  2455. }
  2456.  
  2457. /* This function is called once, at assembler startup time.  This should
  2458.    set up all the tables, etc that the MD part of the assembler needs
  2459.  */
  2460. void
  2461. md_begin()
  2462. {
  2463. /*
  2464.  * md_begin -- set up hash tables with 68000 instructions.
  2465.  * similar to what the vax assembler does.  ---phr
  2466.  */
  2467.     /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  2468.        a copy of it at runtime, adding in the information we want but isn't
  2469.        there.  I think it'd be better to have an awk script hack the table
  2470.        at compile time.  Or even just xstr the table and use it as-is.  But
  2471.        my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  2472.        names.  */
  2473.  
  2474.     register struct m68k_opcode *ins;
  2475.     register struct m68_incant *hack,
  2476.         *slak;
  2477.     register char *retval = 0;        /* empty string, or error msg text */
  2478.     register int i;
  2479.     register char c;
  2480.  
  2481.     if ((op_hash = hash_new()) == NULL)
  2482.         as_fatal("Virtual memory exhausted");
  2483.  
  2484.     obstack_begin(&robyn,4000);
  2485.     for (ins = m68k_opcodes; ins < endop; ins++) {
  2486.         hack=slak=(struct m68_incant *)obstack_alloc(&robyn,sizeof(struct m68_incant));
  2487.         do {
  2488.             slak->m_operands=ins->args;
  2489.             slak->m_opnum=strlen(slak->m_operands)/2;
  2490.             slak->m_opcode=ins->opcode;
  2491.                 /* This is kludgey */
  2492.             slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
  2493.             if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
  2494.                 slak->m_next=(struct m68_incant *)
  2495. obstack_alloc(&robyn,sizeof(struct m68_incant));
  2496.                 ins++;
  2497.             } else
  2498.                 slak->m_next=0;
  2499.             slak=slak->m_next;
  2500.         } while(slak);
  2501.         
  2502.         retval = hash_insert (op_hash, ins->name,(char *)hack);
  2503.             /* Didn't his mommy tell him about null pointers? */
  2504.         if(retval && *retval)
  2505.             as_fatal("Internal Error:  Can't hash %s: %s",ins->name,retval);
  2506.     }
  2507.  
  2508.     for (i = 0; i < sizeof(mklower_table) ; i++)
  2509.         mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
  2510.  
  2511.     for (i = 0 ; i < sizeof(notend_table) ; i++) {
  2512.         notend_table[i] = 0;
  2513.         alt_notend_table[i] = 0;
  2514.     }
  2515.     notend_table[','] = 1;
  2516.     notend_table['{'] = 1;
  2517.     notend_table['}'] = 1;
  2518.     alt_notend_table['a'] = 1;
  2519.     alt_notend_table['A'] = 1;
  2520.     alt_notend_table['d'] = 1;
  2521.     alt_notend_table['D'] = 1;
  2522.     alt_notend_table['#'] = 1;
  2523. }
  2524.  
  2525. #if 0
  2526. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  2527.                    || (*s == ':' && index("aAdD#", s[1]))) \
  2528.                ? 0 : 1)
  2529. #endif
  2530.  
  2531. /* This funciton is called once, before the assembler exits.  It is
  2532.    supposed to do any final cleanup for this part of the assembler.
  2533.  */
  2534. void
  2535. md_end()
  2536. {
  2537. }
  2538.  
  2539. #define MAX_LITTLENUMS 6
  2540.  
  2541. /* Turn a string in input_line_pointer into a floating point constant of type
  2542.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2543.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  2544.  */
  2545. char *
  2546. md_atof(type,litP,sizeP)
  2547. char type;
  2548. char *litP;
  2549. int *sizeP;
  2550. {
  2551.     int    prec;
  2552.     LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2553.     LITTLENUM_TYPE *wordP;
  2554.     char    *t;
  2555.     char    *atof_m68k();
  2556.  
  2557.     switch(type) {
  2558.     case 'f':
  2559.     case 'F':
  2560.     case 's':
  2561.     case 'S':
  2562.         prec = 2;
  2563.         break;
  2564.  
  2565.     case 'd':
  2566.     case 'D':
  2567.     case 'r':
  2568.     case 'R':
  2569.         prec = 4;
  2570.         break;
  2571.  
  2572.     case 'x':
  2573.     case 'X':
  2574.         prec = 6;
  2575.         break;
  2576.  
  2577.     case 'p':
  2578.     case 'P':
  2579.         prec = 6;
  2580.         break;
  2581.  
  2582.     default:
  2583.         *sizeP=0;
  2584.         return "Bad call to MD_ATOF()";
  2585.     }
  2586.     t=atof_m68k(input_line_pointer,type,words);
  2587.     if(t)
  2588.         input_line_pointer=t;
  2589.  
  2590.     *sizeP=prec * sizeof(LITTLENUM_TYPE);
  2591.     for(wordP=words;prec--;) {
  2592.         md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
  2593.         litP+=sizeof(LITTLENUM_TYPE);
  2594.     }
  2595.     return "";    /* Someone should teach Dean about null pointers */
  2596. }
  2597.  
  2598. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  2599.    for use in the a.out file, and stores them in the array pointed to by buf.
  2600.    This knows about the endian-ness of the target machine and does
  2601.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  2602.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  2603.    LITTLENUMS (shorts, here at least)
  2604.  */
  2605. void
  2606. md_number_to_chars(buf,val,n)
  2607. char    *buf;
  2608. long    val;
  2609. int n;
  2610. {
  2611.     switch(n) {
  2612.     case 1:
  2613.         *buf++=val;
  2614.         break;
  2615.     case 2:
  2616.         *buf++=(val>>8);
  2617.         *buf++=val;
  2618.         break;
  2619.     case 4:
  2620.         *buf++=(val>>24);
  2621.         *buf++=(val>>16);
  2622.         *buf++=(val>>8);
  2623.         *buf++=val;
  2624.         break;
  2625.     default:
  2626.         abort();
  2627.     }
  2628. }
  2629.  
  2630. void
  2631. md_number_to_imm(buf,val,n)
  2632. char *buf;
  2633. long val;
  2634. int n;
  2635. {
  2636.     switch(n) {
  2637.     case 1:
  2638.         *buf++=val;
  2639.         break;
  2640.     case 2:
  2641.         *buf++=(val>>8);
  2642.         *buf++=val;
  2643.         break;
  2644.     case 4:
  2645.         *buf++=(val>>24);
  2646.         *buf++=(val>>16);
  2647.         *buf++=(val>>8);
  2648.         *buf++=val;
  2649.         break;
  2650.     default:
  2651.         abort();
  2652.     }
  2653. }
  2654.  
  2655. void
  2656. md_number_to_disp(buf,val,n)
  2657. char    *buf;
  2658. long    val;
  2659. int n;
  2660. {
  2661.     abort();
  2662. }
  2663.  
  2664. void
  2665. md_number_to_field(buf,val,fix)
  2666. char *buf;
  2667. long val;
  2668. #ifdef __STDC__
  2669. void *fix;
  2670. #else
  2671. char *fix;
  2672. #endif
  2673. {
  2674.     abort();
  2675. }
  2676.  
  2677.  
  2678. /* *fragP has been relaxed to its final size, and now needs to have
  2679.    the bytes inside it modified to conform to the new size  There is UGLY
  2680.    MAGIC here. ..
  2681.  */
  2682. void
  2683. md_convert_frag(fragP)
  2684. register fragS *fragP;
  2685. {
  2686.   long disp;
  2687.   long ext;
  2688.  
  2689.   /* Address in gas core of the place to store the displacement.  */
  2690.   register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2691.   /* Address in object code of the displacement.  */
  2692.   register int object_address = fragP -> fr_fix + fragP -> fr_address;
  2693.  
  2694.   know(fragP->fr_symbol);
  2695.  
  2696.   /* The displacement of the address, from current location.  */
  2697.   disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  2698.  
  2699.   switch(fragP->fr_subtype) {
  2700.   case TAB(BCC68000,BYTE):
  2701.   case TAB(BRANCH,BYTE):
  2702.     know(issbyte(disp));
  2703.     if(disp==0)
  2704.       as_warn("short branch with zero offset: use :w");
  2705.     fragP->fr_opcode[1]=disp;
  2706.     ext=0;
  2707.     break;
  2708.   case TAB(DBCC,SHORT):
  2709.     know(issword(disp));
  2710.     ext=2;
  2711.     break;
  2712.   case TAB(BCC68000,SHORT):
  2713.   case TAB(BRANCH,SHORT):
  2714.     know(issword(disp));
  2715.     fragP->fr_opcode[1]=0x00;
  2716.     ext=2;
  2717.     break;
  2718.   case TAB(BRANCH,LONG):
  2719.     if(flagseen['m']) {
  2720.       if(fragP->fr_opcode[0]==0x61) {
  2721.     fragP->fr_opcode[0]= 0x4E;
  2722.     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2723.     subseg_change(SEG_TEXT, 0);
  2724.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2725.     fragP->fr_fix+=4;
  2726.     ext=0;
  2727.       } else if(fragP->fr_opcode[0]==0x60) {
  2728.         fragP->fr_opcode[0]= 0x4E;
  2729.         fragP->fr_opcode[1]= 0xF9;      /* JMP  with ABSL LONG offset */
  2730.         subseg_change(SEG_TEXT, 0);
  2731.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0);
  2732.         fragP->fr_fix+=4;
  2733.         ext=0;
  2734.       }else {
  2735.         as_warn("Long branch offset not supported.");
  2736.       }
  2737.     } else {
  2738.       fragP->fr_opcode[1]=0xff;
  2739.       ext=4;
  2740.     }
  2741.     break;
  2742.   case TAB(BCC68000,LONG):
  2743.     {
  2744.     /* only Bcc 68000 instructions can come here */
  2745.         /* change bcc into b!cc/jmp absl long */
  2746.     fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2747.         fragP->fr_opcode[1] = 0x6;   /* branch offset = 6 */
  2748.         fragP->fr_opcode[2] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2749.         fragP->fr_opcode[3] = 0xf9;  
  2750.         fragP->fr_fix += 2;         /* account for jmp instruction */
  2751.         subseg_change(SEG_TEXT,0);
  2752.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2753.                      fragP->fr_offset,0);
  2754.         fragP->fr_fix += 4;
  2755.         ext=0;
  2756.     }
  2757.     break;
  2758.   case TAB(DBCC,LONG):
  2759.     {
  2760.         /* only DBcc 68000 instructions can come here */
  2761.         /* change dbcc into dbcc/jmp absl long */
  2762.         fragP->fr_opcode[2] = 0x00;  /* branch offset = 4 */
  2763.         fragP->fr_opcode[3] = 0x04;  
  2764.         fragP->fr_opcode[4] = 0x60;  /* put in bra pc+6 */ 
  2765.         fragP->fr_opcode[5] = 0x06;  
  2766.         fragP->fr_opcode[6] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2767.         fragP->fr_opcode[7] = 0xf9;  
  2768.  
  2769.         fragP->fr_fix += 6;         /* account for bra/jmp instructions */
  2770.         subseg_change(SEG_TEXT,0);
  2771.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2772.                      fragP->fr_offset,0);
  2773.         fragP->fr_fix += 4;
  2774.         ext=0;
  2775.     }
  2776.     break;
  2777.   case TAB(FBRANCH,SHORT):
  2778.     know((fragP->fr_opcode[1]&0x40)==0);
  2779.     ext=2;
  2780.     break;
  2781.   case TAB(FBRANCH,LONG):
  2782.     fragP->fr_opcode[1]|=0x40;    /* Turn on LONG bit */
  2783.     ext=4;
  2784.     break;
  2785.   case TAB(PCREL,SHORT):
  2786.     ext=2;
  2787.     break;
  2788.   case TAB(PCREL,LONG):
  2789.     /* The thing to do here is force it to ABSOLUTE LONG, since
  2790.        PCREL is really trying to shorten an ABSOLUTE address anyway */
  2791.     /* JF FOO This code has not been tested */
  2792.     subseg_change(SEG_TEXT,0);
  2793.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2794.     if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  2795.         as_warn("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
  2796.             fragP->fr_opcode[0],fragP->fr_address);
  2797.     fragP->fr_opcode[1]&= ~0x3F;
  2798.     fragP->fr_opcode[1]|=0x39;    /* Mode 7.1 */
  2799.     fragP->fr_fix+=4;
  2800.     /* md_number_to_chars(buffer_address,
  2801.                (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
  2802.                4); */
  2803.     ext=0;
  2804.   }
  2805.   if(ext) {
  2806.     md_number_to_chars(buffer_address,(long)disp,(int)ext);
  2807.     fragP->fr_fix+=ext;
  2808.   }
  2809. }
  2810.  
  2811. /* Force truly undefined symbols to their maximum size, and generally set up
  2812.    the frag list to be relaxed
  2813.  */
  2814. int
  2815. md_estimate_size_before_relax(fragP,segtype)
  2816. register fragS *fragP;
  2817. int segtype;
  2818. {
  2819.     int    old_fix;
  2820.  
  2821.     old_fix=fragP->fr_fix;
  2822.  
  2823.         /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  2824.     switch(fragP->fr_subtype) {
  2825.         case TAB(DBCC,SZ_UNDEF):
  2826.                 if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2827.                         fragP->fr_subtype=TAB(DBCC,SHORT);
  2828.                         fragP->fr_var+=2;
  2829.                         break;
  2830.                 }
  2831.             /* only DBcc 68000 instructions can come here */
  2832.                 /* change dbcc into dbcc/jmp absl long */
  2833.                 fragP->fr_opcode[2] = 0x00;  /* branch offset = 4 */
  2834.                 fragP->fr_opcode[3] = 0x04;  
  2835.                 fragP->fr_opcode[4] = 0x60;  /* put in bra pc+6 */ 
  2836.                 fragP->fr_opcode[5] = 0x06;  
  2837.                 fragP->fr_opcode[6] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2838.                 fragP->fr_opcode[7] = 0xf9;  
  2839.                 fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  2840.                 subseg_change(SEG_TEXT,0);
  2841.                 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2842.                              fragP->fr_offset,0);
  2843.                 fragP->fr_fix += 4;
  2844.                 frag_wane(fragP);
  2845.                 break;
  2846.                 
  2847.         case TAB(BCC68000,SZ_UNDEF):
  2848.                 if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2849.                         fragP->fr_subtype=TAB(BCC68000,BYTE);
  2850.                         break;
  2851.                 }
  2852.             /* only Bcc 68000 instructions can come here */
  2853.                 /* change bcc into b!cc/jmp absl long */
  2854.             fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2855.                 fragP->fr_opcode[1] = 0x6;   /* branch offset = 6 */
  2856.                 fragP->fr_opcode[2] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2857.                 fragP->fr_opcode[3] = 0xf9;  
  2858.                 fragP->fr_fix += 2;         /* account for jmp instruction */
  2859.                 subseg_change(SEG_TEXT,0);
  2860.                 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2861.                              fragP->fr_offset,0);
  2862.                 fragP->fr_fix += 4;
  2863.                 frag_wane(fragP);
  2864.                 break;
  2865.                 
  2866.     case TAB(BRANCH,SZ_UNDEF):
  2867.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2868.                         fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  2869.                         break;
  2870.         } else if(flagseen['m']) {
  2871.           if(fragP->fr_opcode[0]==0x61) {
  2872.             fragP->fr_opcode[0]= 0x4E;
  2873.             fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2874.             subseg_change(SEG_TEXT, 0);
  2875.                     fix_new(fragP, fragP->fr_fix, 4, 
  2876.                 fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2877.             fragP->fr_fix+=4;
  2878.             frag_wane(fragP);
  2879.                   } else if(fragP->fr_opcode[0]==0x60) {
  2880.                     fragP->fr_opcode[0]= 0x4E;
  2881.                     fragP->fr_opcode[1]= 0xF9;  /* JMP  with ABSL LONG offset */
  2882.                     subseg_change(SEG_TEXT, 0);
  2883.                     fix_new(fragP, fragP->fr_fix, 4, 
  2884.                 fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2885.                     fragP->fr_fix+=4;
  2886.                     frag_wane(fragP);
  2887.           } else {
  2888.                     as_warn("Long branch offset to extern symbol not supported.");
  2889.           }
  2890.         } else {    /* Symbol is still undefined.  Make it simple */
  2891.             fix_new(fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol,
  2892.  (symbolS *)0,fragP->fr_offset+4,1);
  2893.             fragP->fr_fix+=4;
  2894.             fragP->fr_opcode[1]=0xff;
  2895.             frag_wane(fragP);
  2896.             break;
  2897.         }
  2898.     default:
  2899.                 break;
  2900.         }
  2901.  
  2902.         /* now that SZ_UNDEF are taken care of, check others */
  2903.         switch(fragP->fr_subtype) {
  2904.         case TAB(BCC68000,BYTE):
  2905.     case TAB(BRANCH,BYTE):
  2906.             /* We can't do a short jump to the next instruction,
  2907.                so we force word mode.  */
  2908.         if(fragP->fr_symbol && fragP->fr_symbol->sy_value==0 &&
  2909.  fragP->fr_symbol->sy_frag==fragP->fr_next) {
  2910.                         fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  2911.             fragP->fr_var+=2;
  2912.         }
  2913.         break;
  2914.     case TAB(FBRANCH,SZ_UNDEF):
  2915.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2916.             fragP->fr_subtype=TAB(FBRANCH,SHORT);
  2917.             fragP->fr_var+=2;
  2918.         } else {
  2919.             fragP->fr_subtype=TAB(FBRANCH,LONG);
  2920.             fragP->fr_var+=4;
  2921.         }
  2922.         break;
  2923.     case TAB(PCREL,SZ_UNDEF):
  2924.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2925.             fragP->fr_subtype=TAB(PCREL,SHORT);
  2926.             fragP->fr_var+=2;
  2927.         } else {
  2928.             fragP->fr_subtype=TAB(PCREL,LONG);
  2929.             fragP->fr_var+=4;
  2930.         }
  2931.         break;
  2932.     default:
  2933.         break;
  2934.     }
  2935.     return fragP->fr_var + fragP->fr_fix - old_fix;
  2936. }
  2937.  
  2938. /* the bit-field entries in the relocation_info struct plays hell 
  2939.    with the byte-order problems of cross-assembly.  So as a hack,
  2940.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  2941.    you there. -KWK */
  2942. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  2943. are symbolnum, most sig. byte first.  Last byte is broken up with
  2944. bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  2945. nibble as nuthin. (on Sun 3 at least) */
  2946. void
  2947. md_ri_to_chars(ri_p, ri)
  2948.      struct relocation_info *ri_p, ri;
  2949. {
  2950.   unsigned char the_bytes[8];
  2951.   
  2952.   /* this is easy */
  2953.   md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  2954.   /* now the fun stuff */
  2955.   the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
  2956.   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  2957.   the_bytes[6] = ri.r_symbolnum & 0x0ff;
  2958.   the_bytes[7] = (((ri.r_pcrel << 7)  & 0x80) | ((ri.r_length << 5) & 0x60) | 
  2959.     ((ri.r_extern << 4)  & 0x10)); 
  2960.   /* now put it back where you found it */
  2961.   bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  2962. }
  2963.  
  2964. #ifndef WORKING_DOT_WORD
  2965. int md_short_jump_size = 4;
  2966. int md_long_jump_size = 6;
  2967.  
  2968. void
  2969. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  2970. char    *ptr;
  2971. long    from_addr,
  2972.     to_addr;
  2973. fragS    *frag;
  2974. symbolS    *to_symbol;
  2975. {
  2976.     long offset;
  2977.  
  2978.     offset = to_addr - (from_addr+2);
  2979.  
  2980.     md_number_to_chars(ptr  ,(long)0x6000,2);
  2981.     md_number_to_chars(ptr+2,(long)offset,2);
  2982. }
  2983.  
  2984. void
  2985. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  2986. char    *ptr;
  2987. long    from_addr,
  2988.     to_addr;
  2989. fragS    *frag;
  2990. symbolS    *to_symbol;
  2991. {
  2992.     long offset;
  2993.  
  2994.     if(flagseen['m']) {
  2995.         offset=to_addr-to_symbol->sy_value;
  2996.         md_number_to_chars(ptr  ,(long)0x4EF9,2);
  2997.         md_number_to_chars(ptr+2,(long)offset,4);
  2998.         fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long int)0,0);
  2999.     } else {
  3000.         offset=to_addr - (from_addr+2);
  3001.         md_number_to_chars(ptr  ,(long)0x60ff,2);
  3002.         md_number_to_chars(ptr+2,(long)offset,4);
  3003.     }
  3004. }
  3005.  
  3006. #endif
  3007. /* Different values of OK tell what its OK to return.  Things that aren't OK are an error (what a shock, no?)
  3008.  
  3009.     0:  Everything is OK
  3010.     10:  Absolute 1:8    only
  3011.     20:  Absolute 0:7    only
  3012.     30:  absolute 0:15    only
  3013.     40:  Absolute 0:31    only
  3014.     50:  absolute 0:127    only
  3015.     55:  absolute -64:63    only
  3016.     60:  absolute -128:127    only
  3017.     70:  absolute 0:4095    only
  3018.     80:  No bignums
  3019.  
  3020. */
  3021. int
  3022. get_num(exp,ok)
  3023. struct m68k_exp *exp;
  3024. int ok;
  3025. {
  3026. #ifdef TEST2
  3027.     long    l = 0;
  3028.  
  3029.     if(!exp->e_beg)
  3030.         return 0;
  3031.     if(*exp->e_beg=='0') {
  3032.         if(exp->e_beg[1]=='x')
  3033.             sscanf(exp->e_beg+2,"%x",&l);
  3034.         else
  3035.             sscanf(exp->e_beg+1,"%O",&l);
  3036.         return l;
  3037.     }
  3038.     return atol(exp->e_beg);
  3039. #else
  3040.     char    *save_in;
  3041.     char    c_save;
  3042.  
  3043.     if(!exp) {
  3044.         /* Can't do anything */
  3045.         return 0;
  3046.     }
  3047.     if(!exp->e_beg || !exp->e_end) {
  3048.         seg(exp)=SEG_ABSOLUTE;
  3049.         adds(exp)=0;
  3050.         subs(exp)=0;
  3051.         offs(exp)= (ok==10) ? 1 : 0;
  3052.         as_warn("Null expression defaults to %ld",offs(exp));
  3053.         return 0;
  3054.     }
  3055.  
  3056.     exp->e_siz=0;
  3057.     if(/* ok!=80 && */exp->e_end[-1]==':' && (exp->e_end-exp->e_beg)>2) {
  3058.         switch(exp->e_end[0]) {
  3059.         case 's':
  3060.         case 'b':
  3061.             exp->e_siz=1;
  3062.             break;
  3063.         case 'w':
  3064.             exp->e_siz=2;
  3065.             break;
  3066.         case 'l':
  3067.             exp->e_siz=3;
  3068.             break;
  3069.         default:
  3070.             as_warn("Unknown size for expression \"%c\"",exp->e_end[0]);
  3071.         }
  3072.         exp->e_end-=2;
  3073.     }
  3074.     c_save=exp->e_end[1];
  3075.     exp->e_end[1]='\0';
  3076.     save_in=input_line_pointer;
  3077.     input_line_pointer=exp->e_beg;
  3078.     switch(expression(&(exp->e_exp))) {
  3079.     case SEG_NONE:
  3080.         /* Do the same thing the VAX asm does */
  3081.         seg(exp)=SEG_ABSOLUTE;
  3082.         adds(exp)=0;
  3083.         subs(exp)=0;
  3084.         offs(exp)=0;
  3085.         if(ok==10) {
  3086.             as_warn("expression out of range: defaulting to 1");
  3087.             offs(exp)=1;
  3088.         }
  3089.         break;
  3090.     case SEG_ABSOLUTE:
  3091.         switch(ok) {
  3092.         case 10:
  3093.             if(offs(exp)<1 || offs(exp)>8) {
  3094.                 as_warn("expression out of range: defaulting to 1");
  3095.                 offs(exp)=1;
  3096.             }
  3097.             break;
  3098.         case 20:
  3099.             if(offs(exp)<0 || offs(exp)>7)
  3100.                 goto outrange;
  3101.             break;
  3102.         case 30:
  3103.             if(offs(exp)<0 || offs(exp)>15)
  3104.                 goto outrange;
  3105.             break;
  3106.         case 40:
  3107.             if(offs(exp)<0 || offs(exp)>32)
  3108.                 goto outrange;
  3109.             break;
  3110.         case 50:
  3111.             if(offs(exp)<0 || offs(exp)>127)
  3112.                 goto outrange;
  3113.             break;
  3114.         case 55:
  3115.             if(offs(exp)<-64 || offs(exp)>63)
  3116.                 goto outrange;
  3117.             break;
  3118.         case 60:
  3119.             if(offs(exp)<-128 || offs(exp)>127)
  3120.                 goto outrange;
  3121.             break;
  3122.         case 70:
  3123.             if(offs(exp)<0 || offs(exp)>4095) {
  3124.             outrange:
  3125.                 as_warn("expression out of range: defaulting to 0");
  3126.                 offs(exp)=0;
  3127.             }
  3128.             break;
  3129.         default:
  3130.             break;
  3131.         }
  3132.         break;
  3133.     case SEG_TEXT:
  3134.     case SEG_DATA:
  3135.     case SEG_BSS:
  3136.     case SEG_UNKNOWN:
  3137.     case SEG_DIFFERENCE:
  3138.         if(ok>=10 && ok<=70) {
  3139.             seg(exp)=SEG_ABSOLUTE;
  3140.             adds(exp)=0;
  3141.             subs(exp)=0;
  3142.             offs(exp)= (ok==10) ? 1 : 0;
  3143.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3144.         }
  3145.         break;
  3146.     case SEG_BIG:
  3147.         if(ok==80 && offs(exp)<0) {    /* HACK! Turn it into a long */
  3148.             LITTLENUM_TYPE words[6];
  3149.  
  3150.             gen_to_words(words,2,8L);/* These numbers are magic! */
  3151.             seg(exp)=SEG_ABSOLUTE;
  3152.             adds(exp)=0;
  3153.             subs(exp)=0;
  3154.             offs(exp)=words[1]|(words[0]<<16);
  3155.         } else if(ok!=0) {
  3156.             seg(exp)=SEG_ABSOLUTE;
  3157.             adds(exp)=0;
  3158.             subs(exp)=0;
  3159.             offs(exp)= (ok==10) ? 1 : 0;
  3160.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3161.         }
  3162.         break;
  3163.     default:
  3164.         abort();
  3165.     }
  3166.     if(input_line_pointer!=exp->e_end+1)
  3167.         as_warn("Ignoring junk after expression");
  3168.     exp->e_end[1]=c_save;
  3169.     input_line_pointer=save_in;
  3170.     if(exp->e_siz) {
  3171.         switch(exp->e_siz) {
  3172.         case 1:
  3173.             if(!isbyte(offs(exp)))
  3174.                 as_warn("expression doesn't fit in BYTE");
  3175.             break;
  3176.         case 2:
  3177.             if(!isword(offs(exp)))
  3178.                 as_warn("expression doesn't fit in WORD");
  3179.             break;
  3180.         }
  3181.     }
  3182.     return offs(exp);
  3183. #endif
  3184. }
  3185.  
  3186. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  3187. void demand_empty_rest_of_line();    /* Hate those extra verbose names */
  3188.  
  3189. void
  3190. s_data1()
  3191. {
  3192.     subseg_new(SEG_DATA,1);
  3193.     demand_empty_rest_of_line();
  3194. }
  3195.  
  3196. void
  3197. s_data2()
  3198. {
  3199.     subseg_new(SEG_DATA,2);
  3200.     demand_empty_rest_of_line();
  3201. }
  3202.  
  3203. void
  3204. s_even()
  3205. {
  3206.     register int temp;
  3207.     register long int temp_fill;
  3208.  
  3209.     temp = 1;        /* JF should be 2? */
  3210.     temp_fill = get_absolute_expression ();
  3211.     if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
  3212.         frag_align (temp, (int)temp_fill);
  3213.     demand_empty_rest_of_line();
  3214. }
  3215.  
  3216. /* s_space is defined in read.c .skip is simply an alias to it. */
  3217.  
  3218. int
  3219. md_parse_option(argP,cntP,vecP)
  3220. char **argP;
  3221. int *cntP;
  3222. char ***vecP;
  3223. {
  3224.     switch(**argP) {
  3225.     case 'l':    /* -l means keep external to 2 bit offset
  3226.                rather than 16 bit one */
  3227.         break;
  3228.  
  3229.     case 'm':
  3230.         /* Gas simply ignores this option! */
  3231.         (*argP)++;
  3232.         if(**argP=='c')
  3233.             (*argP)++;
  3234.         if(!strcmp(*argP,"68000"))
  3235.             flagseen['m']=2;
  3236.         else if(!strcmp(*argP,"68010")) {
  3237. #ifdef M_SUN
  3238.             omagic= 1<<16|OMAGIC;
  3239. #endif
  3240.             flagseen['m']=1;
  3241.         } else if(!strcmp(*argP,"68020"))
  3242.             flagseen['m']=0;
  3243.         else
  3244.             as_warn("Unknown -m option ignored");
  3245.         while(**argP)
  3246.             (*argP)++;
  3247.         break;
  3248.  
  3249.     default:
  3250.         return 0;
  3251.     }
  3252.     return 1;
  3253. }
  3254.  
  3255.  
  3256. #ifdef TEST2
  3257.  
  3258. /* TEST2:  Test md_assemble() */
  3259. /* Warning, this routine probably doesn't work anymore */
  3260.  
  3261. main()
  3262. {
  3263.     struct m68_it the_ins;
  3264.     char buf[120];
  3265.     char *cp;
  3266.     int    n;
  3267.  
  3268.     m68_ip_begin();
  3269.     for(;;) {
  3270.         if(!gets(buf) || !*buf)
  3271.             break;
  3272.         if(buf[0]=='|' || buf[1]=='.')
  3273.             continue;
  3274.         for(cp=buf;*cp;cp++)
  3275.             if(*cp=='\t')
  3276.                 *cp=' ';
  3277.         if(is_label(buf))
  3278.             continue;
  3279.         bzero(&the_ins,sizeof(the_ins));
  3280.         m68_ip(&the_ins,buf);
  3281.         if(the_ins.error) {
  3282.             printf("Error %s in %s\n",the_ins.error,buf);
  3283.         } else {
  3284.             printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
  3285.             for(n=0;n<the_ins.numo;n++)
  3286.                 printf(" 0x%x",the_ins.opcode[n]&0xffff);
  3287.             printf("    ");
  3288.             print_the_insn(&the_ins.opcode[0],stdout);
  3289.             (void)putchar('\n');
  3290.         }
  3291.         for(n=0;n<strlen(the_ins.args)/2;n++) {
  3292.             if(the_ins.operands[n].error) {
  3293.                 printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
  3294.                 continue;
  3295.             }
  3296.             printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
  3297.             if(the_ins.operands[n].b_const)
  3298.                 printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
  3299.             printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
  3300.             if(the_ins.operands[n].b_iadd)
  3301.                 printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
  3302.             (void)putchar('\n');
  3303.         }
  3304.     }
  3305.     m68_ip_end();
  3306.     return 0;
  3307. }
  3308.  
  3309. is_label(str)
  3310. char *str;
  3311. {
  3312.     while(*str==' ')
  3313.         str++;
  3314.     while(*str && *str!=' ')
  3315.         str++;
  3316.     if(str[-1]==':' || str[1]=='=')
  3317.         return 1;
  3318.     return 0;
  3319. }
  3320.  
  3321. print_address(add,fp)
  3322. FILE *fp;
  3323. {
  3324.     fprintf(fp,"%#X",add);
  3325. }
  3326.  
  3327. #endif
  3328.  
  3329. /* Possible states for relaxation:
  3330.  
  3331. 0 0    branch offset    byte    (bra, etc)
  3332. 0 1            word
  3333. 0 2            long
  3334.  
  3335. 1 0    indexed offsets    byte    a0@@(32,d4:w:1) etc
  3336. 1 1            word
  3337. 1 2            long
  3338.  
  3339. 2 0    two-offset index word-word a0@@(32,d4)@@(45) etc
  3340. 2 1            word-long
  3341. 2 2            long-word
  3342. 2 3            long-long
  3343.  
  3344. */
  3345.  
  3346.  
  3347.  
  3348. #ifdef DONTDEF
  3349. abort()
  3350. {
  3351.     printf("ABORT!\n");
  3352.     exit(12);
  3353. }
  3354.  
  3355. char *index(s,c)
  3356. char *s;
  3357. {
  3358.     while(*s!=c) {
  3359.         if(!*s) return 0;
  3360.         s++;
  3361.     }
  3362.     return s;
  3363. }
  3364.  
  3365. bzero(s,n)
  3366. char *s;
  3367. {
  3368.     while(n--)
  3369.         *s++=0;
  3370. }
  3371.  
  3372. print_frags()
  3373. {
  3374.     fragS *fragP;
  3375.     extern fragS *text_frag_root;
  3376.  
  3377.     for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
  3378.         printf("addr %lu  next 0x%x  fix %ld  var %ld  symbol 0x%x  offset %ld\n",
  3379.  fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
  3380.         printf("opcode 0x%x  type %d  subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
  3381.     }
  3382.     fflush(stdout);
  3383.     return 0;
  3384. }
  3385. #endif
  3386.  
  3387. #ifdef DONTDEF
  3388. /*VARARGS1*/
  3389. panic(format,args)
  3390. char *format;
  3391. {
  3392.     fputs("Internal error:",stderr);
  3393.     _doprnt(format,&args,stderr);
  3394.     (void)putc('\n',stderr);
  3395.     as_where();
  3396.     abort();
  3397. }
  3398. #endif
  3399. @
  3400.  
  3401.  
  3402. 1.1
  3403. log
  3404. @Initial revision
  3405. @
  3406. text
  3407. @d2639 1
  3408. d2641 3
  3409. @
  3410.